08scheduling.doxy 7.2 KB

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