340_scheduling_context_hypervisor.doxy 9.7 KB

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