340_scheduling_context_hypervisor.doxy 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 CNRS
  5. * Copyright (C) 2011, 2012 INRIA
  6. * See the file version.doxy for copying conditions.
  7. */
  8. /*! \page SchedulingContextHypervisor Scheduling Context Hypervisor
  9. \section WhatIsTheHypervisor What Is The Hypervisor
  10. StarPU proposes a platform to construct Scheduling Contexts, to
  11. delete and modify them dynamically. A parallel kernel, can thus
  12. be isolated into a scheduling context and interferences between
  13. several parallel kernels are avoided. If users know exactly how
  14. many workers each scheduling context needs, they can assign them to the
  15. contexts at their creation time or modify them during the execution of
  16. the program.
  17. The Scheduling Context Hypervisor Plugin is available for users
  18. who do not dispose of a regular parallelism, who cannot know in
  19. advance the exact size of the context and need to resize the contexts
  20. according to the behavior of the parallel kernels.
  21. The Hypervisor receives information from StarPU concerning the
  22. execution of the tasks, the efficiency of the resources, etc. and it
  23. decides accordingly when and how the contexts can be resized. Basic
  24. strategies of resizing scheduling contexts already exist but a
  25. platform for implementing additional custom ones is available.
  26. \section StartTheHypervisor Start the Hypervisor
  27. The Hypervisor must be initialized once at the beginning of the
  28. application. At this point a resizing policy should be indicated. This
  29. strategy depends on the information the application is able to provide
  30. to the hypervisor as well as on the accuracy needed for the resizing
  31. procedure. For example, the application may be able to provide an
  32. estimation of the workload of the contexts. In this situation the
  33. hypervisor may decide what resources the contexts need. However, if no
  34. information is provided the hypervisor evaluates the behavior of the
  35. resources and of the application and makes a guess about the future.
  36. The hypervisor resizes only the registered contexts.
  37. \section InterrogateTheRuntime Interrogate The Runtime
  38. The runtime provides the hypervisor with information concerning the
  39. behavior of the resources and the application. This is done by using
  40. the <c>performance_counters</c> which represent callbacks indicating
  41. when the resources are idle or not efficient, when the application
  42. submits tasks or when it becomes to slow.
  43. \section TriggerTheHypervisor Trigger the Hypervisor
  44. The resizing is triggered either when the application requires it
  45. (<c> sc_hypervisor_resize_ctxs </c>) or
  46. when the initials distribution of resources alters the performance of
  47. the application (the application is to slow or the resource are idle
  48. for too long time). If the environment
  49. variable <c>SC_HYPERVISOR_TRIGGER_RESIZE</c> is set to <c>speed</c>
  50. the monitored speed of the contexts is compared to a theoretical value
  51. computed with a linear program, and the resizing is triggered
  52. whenever the two values do not correspond. Otherwise, if the environment
  53. variable is set to <c>idle</c> the hypervisor triggers the resizing algorithm
  54. whenever the workers are idle for a period longer than the threshold
  55. indicated by the programmer. When this
  56. happens different resizing strategy are applied that target minimizing
  57. the total execution of the application, the instant speed or the idle
  58. time of the resources.
  59. \section ResizingStrategies Resizing Strategies
  60. The plugin proposes several strategies for resizing the scheduling context.
  61. The <b>Application driven</b> strategy uses users's input concerning the moment when they want to resize the contexts.
  62. Thus, users tag the task that should trigger the resizing
  63. process. One can set directly the field starpu_task::hypervisor_tag or
  64. use the macro ::STARPU_HYPERVISOR_TAG in the function
  65. starpu_task_insert().
  66. \code{.c}
  67. task.hypervisor_tag = 2;
  68. \endcode
  69. or
  70. \code{.c}
  71. starpu_task_insert(&codelet,
  72. ...,
  73. STARPU_HYPERVISOR_TAG, 2,
  74. 0);
  75. \endcode
  76. Then users have to indicate that when a task with the specified tag is executed the contexts should resize.
  77. \code{.c}
  78. sc_hypervisor_resize(sched_ctx, 2);
  79. \endcode
  80. Users can use the same tag to change the resizing configuration of the contexts if they consider it necessary.
  81. \code{.c}
  82. sc_hypervisor_ctl(sched_ctx,
  83. SC_HYPERVISOR_MIN_WORKERS, 6,
  84. SC_HYPERVISOR_MAX_WORKERS, 12,
  85. SC_HYPERVISOR_TIME_TO_APPLY, 2,
  86. NULL);
  87. \endcode
  88. The <b>Idleness</b> based strategy moves workers unused in a certain context to another one needing them.
  89. (see \ref API_SC_Hypervisor_usage)
  90. \code{.c}
  91. int workerids[3] = {1, 3, 10};
  92. int workerids2[9] = {0, 2, 4, 5, 6, 7, 8, 9, 11};
  93. sc_hypervisor_ctl(sched_ctx_id,
  94. SC_HYPERVISOR_MAX_IDLE, workerids, 3, 10000.0,
  95. SC_HYPERVISOR_MAX_IDLE, workerids2, 9, 50000.0,
  96. NULL);
  97. \endcode
  98. The <b>Gflops rate</b> based strategy resizes the scheduling contexts such that they all finish at the same time.
  99. The speed of each of them is computed and once one of them is significantly slower the resizing process is triggered.
  100. In order to do these computations users have to input the total number of instructions needed to be executed by the
  101. parallel kernels and the number of instruction to be executed by each
  102. task.
  103. The number of flops to be executed by a context are passed as
  104. parameter when they are registered to the hypervisor,
  105. (<c>sc_hypervisor_register_ctx(sched_ctx_id, flops)</c>) and the one
  106. to be executed by each task are passed when the task is submitted.
  107. The corresponding field is starpu_task::flops and the corresponding
  108. macro in the function starpu_task_insert() is ::STARPU_FLOPS
  109. (<b>Caution</b>: but take care of passing a double, not an integer,
  110. otherwise parameter passing will be bogus). When the task is executed
  111. the resizing process is triggered.
  112. \code{.c}
  113. task.flops = 100;
  114. \endcode
  115. or
  116. \code{.c}
  117. starpu_task_insert(&codelet,
  118. ...,
  119. STARPU_FLOPS, (double) 100,
  120. 0);
  121. \endcode
  122. The <b>Feft</b> strategy uses a linear program to predict the best distribution of resources
  123. such that the application finishes in a minimum amount of time. As for the <b>Gflops rate </b>
  124. strategy the programmers has to indicate the total number of flops to be executed
  125. when registering the context. This number of flops may be updated dynamically during the execution
  126. of the application whenever this information is not very accurate from the beginning.
  127. The function <c>sc_hypervisor_update_diff_total_flop </c> is called in order add or remove
  128. a difference to the flops left to be executed.
  129. Tasks are provided also the number of flops corresponding to each one of them. During the
  130. execution of the application the hypervisor monitors the consumed flops and recomputes
  131. the time left and the number of resources to use. The speed of each type of resource
  132. is (re)evaluated and inserter in the linear program in order to better adapt to the
  133. needs of the application.
  134. The <b>Teft</b> strategy uses a linear program too, that considers all the types of tasks
  135. and the number of each of them and it tries to allocates resources such that the application
  136. finishes in a minimum amount of time. A previous calibration of StarPU would be useful
  137. in order to have good predictions of the execution time of each type of task.
  138. The types of tasks may be determines directly by the hypervisor when they are submitted.
  139. However there are applications that do not expose all the graph of tasks from the beginning.
  140. In this case in order to let the hypervisor know about all the tasks the function
  141. <c> sc_hypervisor_set_type_of_task </c> will just inform the hypervisor about future tasks
  142. without submitting them right away.
  143. The <b>Ispeed </b> strategy divides the execution of the application in several frames.
  144. For each frame the hypervisor computes the speed of the contexts and tries making them
  145. run at the same speed. The strategy requires less contribution from users as
  146. the hypervisor requires only the size of the frame in terms of flops.
  147. \code{.c}
  148. int workerids[3] = {1, 3, 10};
  149. int workerids2[9] = {0, 2, 4, 5, 6, 7, 8, 9, 11};
  150. sc_hypervisor_ctl(sched_ctx_id,
  151. SC_HYPERVISOR_ISPEED_W_SAMPLE, workerids, 3, 2000000000.0,
  152. SC_HYPERVISOR_ISPEED_W_SAMPLE, workerids2, 9, 200000000000.0,
  153. SC_HYPERVISOR_ISPEED_CTX_SAMPLE, 60000000000.0,
  154. NULL);
  155. \endcode
  156. The <b>Throughput </b> strategy focuses on maximizing the throughput of the resources
  157. and resizes the contexts such that the machine is running at its maximum efficiency
  158. (maximum instant speed of the workers).
  159. \section DefiningANewHypervisorPolicy Defining A New Hypervisor Policy
  160. While Scheduling Context Hypervisor Plugin comes with a variety of
  161. resizing policies (see \ref ResizingStrategies), it may sometimes be
  162. desirable to implement custom policies to address specific problems.
  163. The API described below allows users to write their own resizing policy.
  164. Here an example of how to define a new policy
  165. \code{.c}
  166. struct sc_hypervisor_policy dummy_policy =
  167. {
  168. .handle_poped_task = dummy_handle_poped_task,
  169. .handle_pushed_task = dummy_handle_pushed_task,
  170. .handle_idle_cycle = dummy_handle_idle_cycle,
  171. .handle_idle_end = dummy_handle_idle_end,
  172. .handle_post_exec_hook = dummy_handle_post_exec_hook,
  173. .custom = 1,
  174. .name = "dummy"
  175. };
  176. \endcode
  177. */