08scheduling.doxy 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * This file is part of the StarPU Handbook.
  3. * Copyright (C) 2009--2011 Universit@'e de Bordeaux 1
  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>dm</b> (deque model) scheduler uses task execution performance models into account to
  38. perform a HEFT-similar scheduling strategy: it schedules tasks where their
  39. termination time will be minimal. The difference with HEFT is that <b>dm</b>
  40. schedules tasks as soon as they become available, and thus in the order they
  41. become available, without taking priorities into account.
  42. The <b>dmda</b> (deque model data aware) scheduler is similar to dm, but it also takes
  43. into account data transfer time.
  44. The <b>dmdar</b> (deque model data aware ready) scheduler is similar to dmda,
  45. but it also sorts tasks on per-worker queues by number of already-available data
  46. buffers on the target device.
  47. The <b>dmdas</b> (deque model data aware sorted) scheduler is similar to dmdar,
  48. except that it sorts tasks by priority order, which allows to become even closer
  49. to HEFT by respecting priorities after having made the scheduling decision (but
  50. it still schedules tasks in the order they become available).
  51. The <b>heft</b> (heterogeneous earliest finish time) scheduler is a deprecated
  52. alias for <b>dmda</b>.
  53. The <b>pheft</b> (parallel HEFT) scheduler is similar to dmda, it also supports
  54. parallel tasks (still experimental). Should not be used when several contexts using
  55. it are being executed simultaneously.
  56. The <b>peager</b> (parallel eager) scheduler is similar to eager, it also
  57. supports parallel tasks (still experimental). Should not be used when several
  58. contexts using it are being executed simultaneously.
  59. \section TaskDistributionVsDataTransfer Task Distribution Vs Data Transfer
  60. Distributing tasks to balance the load induces data transfer penalty. StarPU
  61. thus needs to find a balance between both. The target function that the
  62. scheduler <c>dmda</c> of StarPU
  63. tries to minimize is <c>alpha * T_execution + beta * T_data_transfer</c>, where
  64. <c>T_execution</c> is the estimated execution time of the codelet (usually
  65. accurate), and <c>T_data_transfer</c> is the estimated data transfer time. The
  66. latter is estimated based on bus calibration before execution start,
  67. i.e. with an idle machine, thus without contention. You can force bus
  68. re-calibration by running the tool <c>starpu_calibrate_bus</c>. The
  69. beta parameter defaults to <c>1</c>, but it can be worth trying to tweak it
  70. by using <c>export STARPU_SCHED_BETA=2</c> for instance, since during
  71. real application execution, contention makes transfer times bigger.
  72. This is of course imprecise, but in practice, a rough estimation
  73. already gives the good results that a precise estimation would give.
  74. \section Power-basedScheduling Power-based Scheduling
  75. If the application can provide some power performance model (through
  76. the field starpu_codelet::power_model), StarPU will
  77. take it into account when distributing tasks. The target function that
  78. the scheduler <c>dmda</c> minimizes becomes <c>alpha * T_execution +
  79. beta * T_data_transfer + gamma * Consumption</c> , where <c>Consumption</c>
  80. is the estimated task consumption in Joules. To tune this parameter, use
  81. <c>export STARPU_SCHED_GAMMA=3000</c> for instance, to express that each Joule
  82. (i.e kW during 1000us) is worth 3000us execution time penalty. Setting
  83. <c>alpha</c> and <c>beta</c> to zero permits to only take into account power consumption.
  84. This is however not sufficient to correctly optimize power: the scheduler would
  85. simply tend to run all computations on the most energy-conservative processing
  86. unit. To account for the consumption of the whole machine (including idle
  87. processing units), the idle power of the machine should be given by setting
  88. <c>export STARPU_IDLE_POWER=200</c> for 200W, for instance. This value can often
  89. be obtained from the machine power supplier.
  90. The power actually consumed by the total execution can be displayed by setting
  91. <c>export STARPU_PROFILING=1 STARPU_WORKER_STATS=1</c> .
  92. On-line task consumption measurement is currently only supported through the
  93. <c>CL_PROFILING_POWER_CONSUMED</c> OpenCL extension, implemented in the MoviSim
  94. simulator. Applications can however provide explicit measurements by
  95. using the function starpu_perfmodel_update_history() (examplified in \ref PerformanceModelExample
  96. with the <c>power_model</c> performance model). Fine-grain
  97. measurement is often not feasible with the feedback provided by the hardware, so
  98. the user can for instance run a given task a thousand times, measure the global
  99. consumption for that series of tasks, divide it by a thousand, repeat for
  100. varying kinds of tasks and task sizes, and eventually feed StarPU
  101. with these manual measurements through starpu_perfmodel_update_history().
  102. \section StaticScheduling Static Scheduling
  103. In some cases, one may want to force some scheduling, for instance force a given
  104. set of tasks to GPU0, another set to GPU1, etc. while letting some other tasks
  105. be scheduled on any other device. This can indeed be useful to guide StarPU into
  106. some work distribution, while still letting some degree of dynamism. For
  107. instance, to force execution of a task on CUDA0:
  108. \code{.c}
  109. task->execute_on_a_specific_worker = 1;
  110. task->worker = starpu_worker_get_by_type(STARPU_CUDA_WORKER, 0);
  111. \endcode
  112. Note however that using scheduling contexts while statically scheduling tasks on workers
  113. could be tricky. Be careful to schedule the tasks exactly on the workers of the corresponding
  114. contexts, otherwise the workers' corresponding scheduling structures may not be allocated or
  115. the execution of the application may deadlock. Moreover, the hypervisor should not be used when
  116. statically scheduling tasks.
  117. \section DefiningANewSchedulingPolicy Defining A New Scheduling Policy
  118. A full example showing how to define a new scheduling policy is available in
  119. the StarPU sources in the directory <c>examples/scheduler/</c>.
  120. See \ref API_Scheduling_Policy
  121. \code{.c}
  122. static struct starpu_sched_policy dummy_sched_policy = {
  123. .init_sched = init_dummy_sched,
  124. .deinit_sched = deinit_dummy_sched,
  125. .add_workers = dummy_sched_add_workers,
  126. .remove_workers = dummy_sched_remove_workers,
  127. .push_task = push_task_dummy,
  128. .push_prio_task = NULL,
  129. .pop_task = pop_task_dummy,
  130. .post_exec_hook = NULL,
  131. .pop_every_task = NULL,
  132. .policy_name = "dummy",
  133. .policy_description = "dummy scheduling strategy"
  134. };
  135. \endcode
  136. */