08scheduling.doxy 7.4 KB

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