350_scheduling_policy_definition.doxy 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Simon Archipoff
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. /*! \page HowToDefineANewSchedulingPolicy How To Define A New Scheduling Policy
  18. \section NewSchedulingPolicy_Introduction Introduction
  19. StarPU provides two ways of defining a scheduling policy, a basic monolithic
  20. way, and a modular way.
  21. The basic monolithic way is directly connected with the core of StarPU, which
  22. means that the policy then has to handle all performance details, such as data
  23. prefetching, task performance model calibration, worker locking, etc.
  24. <c>examples/scheduler/dummy_sched.c</c> is a trivial example which does not
  25. handle this, and thus e.g. does not achieve any data prefetching or smart
  26. scheduling.
  27. The modular way allows to implement just one component, and
  28. reuse existing components to cope with all these details.
  29. <c>examples/scheduler/dummy_modular_sched.c</c> is a trivial example very
  30. similar to <c>dummy_sched.c</c>, but implemented as a component, which allows to
  31. assemble it with other components, and notably get data prefetching support for
  32. free, and task performance model calibration is properly performed, which allows
  33. to easily extend it into taking task duration into account, etc.
  34. \section SchedulingHelpers Helper functions for defining a scheduling policy (Basic or modular)
  35. Make sure to have a look at the \ref API_Scheduling_Policy section, which
  36. provides a complete list of the functions available for writing advanced schedulers.
  37. This includes getting an estimation for a task computation completion with
  38. starpu_task_expected_length(), for the required data transfers with
  39. starpu_task_expected_data_transfer_time_for(), for the required energy with
  40. starpu_task_expected_energy(), etc. Per-worker variants are also available with
  41. starpu_task_worker_expected_length(), etc. Other
  42. useful functions include starpu_transfer_bandwidth(), starpu_transfer_latency(),
  43. starpu_transfer_predict(), ...
  44. One can also directly test the presence of a data handle with starpu_data_is_on_node().
  45. Prefetches can be triggered by calling either starpu_prefetch_task_input_for(),
  46. starpu_idle_prefetch_task_input(), starpu_prefetch_task_input_for_prio(), or
  47. starpu_idle_prefetch_task_input_for_prio(). The <c>_prio</c> versions allow to
  48. specify a priority for the transfer (instead of taking the task priority by
  49. default). These prefetches are only processed when there are no fetch data
  50. requests (i.e. a task is waiting for it) to process. The <c>_idle</c> versions
  51. queue the transfers on the idle prefetch queue, which is only processed when
  52. there are no non-idle prefetch to process.
  53. starpu_get_prefetch_flag() is a convenient helper for checking the value of the
  54. \ref STARPU_PREFETCH environment variable.
  55. Usual functions can be used on tasks, for instance one can use the following to
  56. get the data size for a task.
  57. \code{.c}
  58. size = 0;
  59. write = 0;
  60. if (task->cl)
  61. for (i = 0; i < STARPU_TASK_GET_NBUFFERS(task); i++)
  62. {
  63. starpu_data_handle_t data = STARPU_TASK_GET_HANDLE(task, i)
  64. size_t datasize = starpu_data_get_size(data);
  65. size += datasize;
  66. if (STARPU_TASK_GET_MODE(task, i) & STARPU_W)
  67. write += datasize;
  68. }
  69. \endcode
  70. Task queues can be implemented with the starpu_task_list functions.
  71. Access to the \c hwloc topology is available with starpu_worker_get_hwloc_obj().
  72. \section DefiningANewBasicSchedulingPolicy Defining A New Basic Scheduling Policy
  73. A full example showing how to define a new scheduling policy is available in
  74. the StarPU sources in <c>examples/scheduler/dummy_sched.c</c>.
  75. The scheduler has to provide methods:
  76. \code{.c}
  77. static struct starpu_sched_policy dummy_sched_policy =
  78. {
  79. .init_sched = init_dummy_sched,
  80. .deinit_sched = deinit_dummy_sched,
  81. .add_workers = dummy_sched_add_workers,
  82. .remove_workers = dummy_sched_remove_workers,
  83. .push_task = push_task_dummy,
  84. .pop_task = pop_task_dummy,
  85. .policy_name = "dummy",
  86. .policy_description = "dummy scheduling strategy"
  87. };
  88. \endcode
  89. The idea is that when a task becomes ready for execution, the
  90. starpu_sched_policy::push_task method is called to give the ready task to the
  91. scheduler. When a worker is idle, the starpu_sched_policy::pop_task method is
  92. called to get a task from the scheduler. It is up to the
  93. scheduler to implement what is between. A simple eager scheduler is for instance
  94. to make starpu_sched_policy::push_task push the task to a global list, and make
  95. starpu_sched_policy::pop_task pop from this list. A scheduler can also use
  96. starpu_push_local_task() to directly push tasks to a per-worker queue, and then
  97. starpu does not even need to implement starpu_sched_policy::pop_task.
  98. If there are no ready tasks within the scheduler, it can just return \c NULL, and
  99. the worker will sleep.
  100. The \ref starpu_sched_policy section provides the exact rules that govern the
  101. methods of the policy.
  102. One can enumerate the workers with this iterator:
  103. \code{.c}
  104. struct starpu_worker_collection *workers = starpu_sched_ctx_get_worker_collection(sched_ctx_id);
  105. struct starpu_sched_ctx_iterator it;
  106. workers->init_iterator(workers, &it);
  107. while(workers->has_next(workers, &it))
  108. {
  109. unsigned worker = workers->get_next(workers, &it);
  110. ...
  111. }
  112. \endcode
  113. To provide synchronization between workers, a per-worker lock exists to protect
  114. the data structures of a given worker. It is acquired around scheduler methods,
  115. so that the scheduler does not need any additional mutex to protect its per-worker data.
  116. In case the scheduler wants to access another scheduler's data, it should use
  117. starpu_worker_lock() and starpu_worker_unlock().
  118. Calling \code{.c}starpu_worker_lock(B)\endcode from a worker \c A will however thus make
  119. worker \c A wait for worker \c B to complete its scheduling method. That may be
  120. a problem if that method takes a long time, because it is e.g. computing a
  121. heuristic or waiting for another mutex, or even cause deadlocks if worker \c B is
  122. calling \code{.c}starpu_worker_lock(A)\endcode at the same time. In such a case, worker \c B must
  123. call starpu_worker_relax_on() and starpu_worker_relax_off() around the section
  124. which potentially blocks (and does not actually need protection). While a worker
  125. is in relaxed mode, e.g. between a pair of starpu_worker_relax_on() and
  126. starpu_worker_relax_off() calls, its state can be altered by other threads: for
  127. instance, worker \c A can push tasks for worker \c B. In consequence, worker \c B
  128. must re-assess its state after \code{.c}starpu_worker_relax_off(B)\endcode, such as taking
  129. possible new tasks pushed to its queue into account.
  130. When the starpu_sched_policy::push_task method has pushed a task for another
  131. worker, one has to call starpu_wake_worker_relax_light() so that the worker wakes up
  132. and picks it. If the task was pushed on a shared queue, one may want to only
  133. wake one idle worker. An example doing this is available in
  134. <c>src/sched_policies/eager_central_policy.c</c>.
  135. A pointer to one data structure specific to the scheduler can be set with
  136. starpu_sched_ctx_set_policy_data() and fetched with
  137. starpu_sched_ctx_get_policy_data(). Per-worker data structures can then be
  138. store in it by allocating a \ref STARPU_NMAXWORKERS -sized array of structures indexed
  139. by workers.
  140. A variety of examples of
  141. advanced schedulers can be read in <c>src/sched_policies</c>, for
  142. instance <c>random_policy.c</c>, <c>eager_central_policy.c</c>,
  143. <c>work_stealing_policy.c</c> Code protected by
  144. <c>if (_starpu_get_nsched_ctxs() > 1)</c> can be ignored, this is for scheduling
  145. contexts, which is an experimental feature.
  146. \section DefiningANewModularSchedulingPolicy Defining A New Modular Scheduling Policy
  147. StarPU's Modularized Schedulers are made of individual Scheduling Components
  148. Modularizedly assembled as a Scheduling Tree. Each Scheduling Component has an
  149. unique purpose, such as prioritizing tasks or mapping tasks over resources.
  150. A typical Scheduling Tree is shown below.
  151. <pre>
  152. |
  153. starpu_push_task |
  154. |
  155. v
  156. Fifo_Component
  157. | ^
  158. Push | | Can_Push
  159. v |
  160. Eager_Component
  161. | ^
  162. | |
  163. v |
  164. --------><-------------------><---------
  165. | ^ | ^
  166. Push | | Can_Push Push | | Can_Push
  167. v | v |
  168. Fifo_Component Fifo_Component
  169. | ^ | ^
  170. Pull | | Can_Pull Pull | | Can_Pull
  171. v | v |
  172. Worker_Component Worker_Component
  173. | |
  174. starpu_pop_task | |
  175. v v
  176. </pre>
  177. When a task is pushed by StarPU in a Modularized Scheduler, the task moves from
  178. a Scheduling Component to an other, following the hierarchy of the
  179. Scheduling Tree, and is stored in one of the Scheduling Components of the
  180. strategy.
  181. When a worker wants to pop a task from the Modularized Scheduler, the
  182. corresponding Worker Component of the Scheduling Tree tries to pull a task from
  183. its parents, following the hierarchy, and gives it to the worker if it succeded
  184. to get one.
  185. \subsection Interface
  186. Each Scheduling Component must follow the following pre-defined Interface
  187. to be able to interact with other Scheduling Components.
  188. - push_task (child_component, Task) \n
  189. The calling Scheduling Component transfers a task to its
  190. Child Component. When the Push function returns, the task no longer
  191. belongs to the calling Component. The Modularized Schedulers'
  192. model relies on this function to perform prefetching.
  193. See starpu_sched_component::push_task for more details
  194. - pull_task (parent_component, caller_component) -> Task \n
  195. The calling Scheduling Component requests a task from
  196. its Parent Component. When the Pull function ends, the returned
  197. task belongs to the calling Component.
  198. See starpu_sched_component::pull_task for more details
  199. - can_push (caller_component, parent_component) \n
  200. The calling Scheduling Component notifies its Parent Component that
  201. it is ready to accept new tasks.
  202. See starpu_sched_component::can_push for more details
  203. - can_pull (caller_component, child_component) \n
  204. The calling Scheduling Component notifies its Child Component
  205. that it is ready to give new tasks.
  206. See starpu_sched_component::can_pull for more details
  207. The components also provide the following useful methods:
  208. - starpu_sched_component::estimated_load provides an estimated load of
  209. the component
  210. - starpu_sched_component::estimated_end provides an estimated date of
  211. availability of workers behind the component, after processing tasks in
  212. the component and below.
  213. This is computed only if the estimated field of the tasks have been set
  214. before passing it to the component.
  215. \subsection BuildAModularizedScheduler Building a Modularized Scheduler
  216. \subsubsection PreImplementedComponents Pre-implemented Components
  217. StarPU is currently shipped with the following four Scheduling Components :
  218. - Storage Components : Fifo, Prio \n
  219. Components which store tasks. They can also prioritize them if
  220. they have a defined priority. It is possible to define a threshold
  221. for those Components following two criterias : the number of tasks
  222. stored in the Component, or the sum of the expected length of all
  223. tasks stored in the Component. When a push operation tries to queue a
  224. task beyond the threshold, the push fails. When some task leaves the
  225. queue (and thus possibly more tasks can fit), this component calls
  226. can_push from ancestors.
  227. - Resource-Mapping Components : Mct, Heft, Eager, Random, Work-Stealing \n
  228. "Core" of the Scheduling Strategy, those Components are the
  229. ones who make scheduling choices between their children components.
  230. - Worker Components : Worker \n
  231. Each Worker Component modelizes a concrete worker, and copes with the
  232. technical tricks of interacting with the StarPU core. Modular schedulers
  233. thus usually have them at the bottom of their component tree.
  234. - Special-Purpose Components : Perfmodel_Select, Best_Implementation \n
  235. Components dedicated to original purposes. The Perfmodel_Select
  236. Component decides which Resource-Mapping Component should be used to
  237. schedule a task: a component that assumes tasks with a calibrated
  238. performance model; a component for non-yet-calibrated tasks, that will
  239. distribute them to get measurements done as quickly as possible; and a
  240. component that takes the tasks without performance models.\n
  241. The Best_Implementation Component chooses which
  242. implementation of a task should be used on the chosen resource.
  243. \subsubsection ProgressionAndValidationRules Progression And Validation Rules
  244. Some rules must be followed to ensure the correctness of a Modularized
  245. Scheduler :
  246. - At least one Storage Component without threshold is needed in a
  247. Modularized Scheduler, to store incoming tasks from StarPU. It can for
  248. instance be a global component at the top of the tree, or one component
  249. per worker at the bottom of the tree, or intermediate assemblies. The
  250. important point is that the starpu_sched_component::push_task call at the top can not
  251. fail, so there has to be a storage component without threshold between
  252. the top of the tree and the first storage component with threshold, or
  253. the workers themselves.
  254. - At least one Resource-Mapping Component is needed in a Modularized
  255. Scheduler. Resource-Mapping Components are the only ones which can make
  256. scheduling choices, and so the only ones which can have several child.
  257. \subsubsection ModularizedSchedulerLocking Locking in modularized schedulers
  258. Most often, components do not need to take locks. This allows e.g. the push
  259. operation to be called in parallel when tasks get released in parallel from
  260. different workers which have completed different ancestor tasks.
  261. When a component has internal information which needs to be kept coherent, the
  262. component can define its own lock at take it as it sees fit, e.g. to protect a
  263. task queue. This may however limit scalability of the scheduler. Conversely,
  264. since push and pull operations will be called concurrently from different
  265. workers, the component might prefer to use a central mutex to serialize all
  266. scheduling decisions to avoid pathological cases (all push calls decide to put
  267. their task on the same target)
  268. \subsubsection ImplementAModularizedScheduler Implementing a Modularized Scheduler
  269. The following code shows how to implement a Tree-Eager-Prefetching Scheduler.
  270. \code{.c}
  271. static void initialize_eager_prefetching_center_policy(unsigned sched_ctx_id)
  272. {
  273. /* The eager component will decide for each task which worker will run it,
  274. * and we want fifos both above and below the component */
  275. starpu_sched_component_initialize_simple_scheduler(
  276. starpu_sched_component_eager_create, NULL,
  277. STARPU_SCHED_SIMPLE_DECIDE_WORKERS |
  278. STARPU_SCHED_SIMPLE_FIFO_ABOVE |
  279. STARPU_SCHED_SIMPLE_FIFOS_BELOW,
  280. sched_ctx_id);
  281. }
  282. /* Properly destroy the Scheduling Tree and all its Components */
  283. static void deinitialize_eager_prefetching_center_policy(unsigned sched_ctx_id)
  284. {
  285. struct starpu_sched_tree * tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  286. starpu_sched_tree_destroy(tree);
  287. }
  288. /* Initializing the starpu_sched_policy struct associated to the Modularized
  289. * Scheduler : only the init_sched and deinit_sched needs to be defined to
  290. * implement a Modularized Scheduler */
  291. struct starpu_sched_policy _starpu_sched_tree_eager_prefetching_policy =
  292. {
  293. .init_sched = initialize_eager_prefetching_center_policy,
  294. .deinit_sched = deinitialize_eager_prefetching_center_policy,
  295. .add_workers = starpu_sched_tree_add_workers,
  296. .remove_workers = starpu_sched_tree_remove_workers,
  297. .push_task = starpu_sched_tree_push_task,
  298. .pop_task = starpu_sched_tree_pop_task,
  299. .pre_exec_hook = starpu_sched_component_worker_pre_exec_hook,
  300. .post_exec_hook = starpu_sched_component_worker_post_exec_hook,
  301. .pop_every_task = NULL,
  302. .policy_name = "tree-eager-prefetching",
  303. .policy_description = "eager with prefetching tree policy"
  304. };
  305. \endcode
  306. starpu_sched_component_initialize_simple_scheduler() is a helper function which
  307. makes it very trivial to assemble a modular scheduler around a scheduling
  308. decision component as seen above (here, a dumb eager decision component). Most
  309. often a modular scheduler can be implemented that way.
  310. A modular scheduler can also be constructed hierarchically with
  311. starpu_sched_component_composed_recipe_create().
  312. That modular scheduler can also be built by hand in the following way:
  313. \code{.c}
  314. #define _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT 2
  315. #define _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT 1000000000.0
  316. static void initialize_eager_prefetching_center_policy(unsigned sched_ctx_id)
  317. {
  318. unsigned ntasks_threshold = _STARPU_SCHED_NTASKS_THRESHOLD_DEFAULT;
  319. double exp_len_threshold = _STARPU_SCHED_EXP_LEN_THRESHOLD_DEFAULT;
  320. [...]
  321. starpu_sched_ctx_create_worker_collection
  322. (sched_ctx_id, STARPU_WORKER_LIST);
  323. /* Create the Scheduling Tree */
  324. struct starpu_sched_tree * t = starpu_sched_tree_create(sched_ctx_id);
  325. /* The Root Component is a Flow-control Fifo Component */
  326. t->root = starpu_sched_component_fifo_create(NULL);
  327. /* The Resource-mapping Component of the strategy is an Eager Component
  328. */
  329. struct starpu_sched_component *eager_component = starpu_sched_component_eager_create(NULL);
  330. /* Create links between Components : the Eager Component is the child
  331. * of the Root Component */
  332. starpu_sched_component_connect(t->root, eager_component);
  333. /* A task threshold is set for the Flow-control Components which will
  334. * be connected to Worker Components. By doing so, this Modularized
  335. * Scheduler will be able to perform some prefetching on the resources
  336. */
  337. struct starpu_sched_component_fifo_data fifo_data =
  338. {
  339. .ntasks_threshold = ntasks_threshold,
  340. .exp_len_threshold = exp_len_threshold,
  341. };
  342. unsigned i;
  343. for(i = 0; i < starpu_worker_get_count() + starpu_combined_worker_get_count(); i++)
  344. {
  345. /* Each Worker Component has a Flow-control Fifo Component as
  346. * father */
  347. struct starpu_sched_component * worker_component = starpu_sched_component_worker_new(i);
  348. struct starpu_sched_component * fifo_component = starpu_sched_component_fifo_create(&fifo_data);
  349. starpu_sched_component_connect(fifo_component, worker_component);
  350. /* Each Flow-control Fifo Component associated to a Worker
  351. * Component is linked to the Eager Component as one of its
  352. * children */
  353. starpu_sched_component_connect(eager_component, fifo_component);
  354. }
  355. starpu_sched_tree_update_workers(t);
  356. starpu_sched_ctx_set_policy_data(sched_ctx_id, (void*)t);
  357. }
  358. /* Properly destroy the Scheduling Tree and all its Components */
  359. static void deinitialize_eager_prefetching_center_policy(unsigned sched_ctx_id)
  360. {
  361. struct starpu_sched_tree * tree = (struct starpu_sched_tree*)starpu_sched_ctx_get_policy_data(sched_ctx_id);
  362. starpu_sched_tree_destroy(tree);
  363. starpu_sched_ctx_delete_worker_collection(sched_ctx_id);
  364. }
  365. /* Initializing the starpu_sched_policy struct associated to the Modularized
  366. * Scheduler : only the init_sched and deinit_sched needs to be defined to
  367. * implement a Modularized Scheduler */
  368. struct starpu_sched_policy _starpu_sched_tree_eager_prefetching_policy =
  369. {
  370. .init_sched = initialize_eager_prefetching_center_policy,
  371. .deinit_sched = deinitialize_eager_prefetching_center_policy,
  372. .add_workers = starpu_sched_tree_add_workers,
  373. .remove_workers = starpu_sched_tree_remove_workers,
  374. .push_task = starpu_sched_tree_push_task,
  375. .pop_task = starpu_sched_tree_pop_task,
  376. .pre_exec_hook = starpu_sched_component_worker_pre_exec_hook,
  377. .post_exec_hook = starpu_sched_component_worker_post_exec_hook,
  378. .pop_every_task = NULL,
  379. .policy_name = "tree-eager-prefetching",
  380. .policy_description = "eager with prefetching tree policy"
  381. };
  382. \endcode
  383. Other modular scheduler examples can be seen in <c>src/sched_policies/modular_*.c</c>
  384. For instance, \c modular-heft-prio needs performance models, decides
  385. memory nodes, uses prioritized fifos above and below, and decides the best
  386. implementation.
  387. If unsure on the result of the modular scheduler construction, you can run a
  388. simple application with FxT enabled (see \ref GeneratingTracesWithFxT), and open
  389. the generated file \c trace.html in a web-browser.
  390. \subsection ModularizedSchedulersAndParallelTasks Management of parallel task
  391. At the moment, parallel tasks can be managed in modularized schedulers through
  392. combined workers: instead of connecting a scheduling component to a worker
  393. component, one can connect it to a combined worker component (i.e. a worker
  394. component created with a combined worker id). That component will handle
  395. creating task aliases for parallel execution and push them to the different
  396. workers components.
  397. \subsection WriteASchedulingComponent Writing a Scheduling Component
  398. \subsubsection GenericSchedulingComponent Generic Scheduling Component
  399. Each Scheduling Component is instantiated from a Generic Scheduling Component,
  400. which implements a generic version of the Interface. The generic implementation
  401. of Pull, Can_Pull and Can_Push functions are recursive calls to their parents
  402. (respectively to their children). However, as a Generic Scheduling Component do
  403. not know how much children it will have when it will be instantiated, it does
  404. not implement the Push function.
  405. \subsubsection InstantiationRedefineInterface Instantiation : Redefining the Interface
  406. A Scheduling Component must implement all the functions of the Interface. It is
  407. so necessary to implement a Push function to instantiate a Scheduling Component.
  408. The implemented Push function is the "fingerprint" of a Scheduling Component.
  409. Depending on how functionalities or properties programmers want to give
  410. to the Scheduling Component they are implementing, it is possible to reimplement
  411. all the functions of the Interface. For example, a Flow-control Component
  412. reimplements the Pull and the Can_Push functions of the Interface, allowing
  413. to catch the generic recursive calls of these functions. The Pull function of
  414. a Flow-control Component can, for example, pop a task from the local storage
  415. queue of the Component, and give it to the calling Component which asks for it.
  416. \subsubsection DetailedProgressionAndValidationRules Detailed Progression and Validation Rules
  417. - A Reservoir is a Scheduling Component which redefines a Push and a Pull
  418. function, in order to store tasks into it. A Reservoir delimit Scheduling
  419. Areas in the Scheduling Tree.
  420. - A Pump is the engine source of the Scheduler : it pushes/pulls tasks
  421. to/from a Scheduling Component to an other. Native Pumps of a Scheduling
  422. Tree are located at the root of the Tree (incoming Push calls from StarPU),
  423. and at the leafs of the Tree (Pop calls coming from StarPU Workers).
  424. Pre-implemented Scheduling Components currently shipped with Pumps are
  425. Flow-Control Components and the Resource-Mapping Component Heft, within
  426. their defined Can_Push functions.
  427. - A correct Scheduling Tree requires a Pump per Scheduling Area and per
  428. Execution Flow.
  429. The Tree-Eager-Prefetching Scheduler shown in Section
  430. \ref ImplementAModularizedScheduler follows the previous assumptions :
  431. <pre>
  432. starpu_push_task
  433. <b>Pump</b>
  434. |
  435. Area 1 |
  436. |
  437. v
  438. -----------------------Fifo_Component-----------------------------
  439. <b>Pump</b>
  440. | ^
  441. Push | | Can_Push
  442. v |
  443. Area 2 Eager_Component
  444. | ^
  445. | |
  446. v |
  447. --------><-------------------><---------
  448. | ^ | ^
  449. Push | | Can_Push Push | | Can_Push
  450. v | v |
  451. -----Fifo_Component-----------------------Fifo_Component----------
  452. | ^ | ^
  453. Pull | | Can_Pull Pull | | Can_Pull
  454. Area 3 v | v |
  455. <b>Pump</b> <b>Pump</b>
  456. Worker_Component Worker_Component
  457. </pre>
  458. \section GraphScheduling Graph-based Scheduling
  459. For performance reasons, most of the schedulers shipped with StarPU use simple
  460. list-scheduling heuristics, assuming that the application has already set
  461. priorities. This is why they do their scheduling between when tasks become
  462. available for execution and when a worker becomes idle, without looking at the
  463. task graph.
  464. Other heuristics can however look at the task graph. Recording the task graph
  465. is expensive, so it is not available by default, the scheduling heuristic has
  466. to set \c _starpu_graph_record to \c 1 from the initialization function, to make it
  467. available. Then the <c>_starpu_graph*</c> functions can be used.
  468. <c>src/sched_policies/graph_test_policy.c</c> is an example of simple greedy
  469. policy which automatically computes priorities by bottom-up rank.
  470. The idea is that while the application submits tasks, they are only pushed
  471. to a bag of tasks. When the application is finished with submitting tasks,
  472. it calls starpu_do_schedule() (or starpu_task_wait_for_all(), which calls
  473. starpu_do_schedule()), and the starpu_sched_policy::do_schedule method of the
  474. scheduler is called. This method calls \c _starpu_graph_compute_depths() to compute
  475. the bottom-up ranks, and then uses these ranks to set priorities over tasks.
  476. It then has two priority queues, one for CPUs, and one for GPUs, and uses a dumb
  477. heuristic based on the duration of the task over CPUs and GPUs to decide between
  478. the two queues. CPU workers can then pop from the CPU priority queue, and GPU
  479. workers from the GPU priority queue.
  480. \section DebuggingScheduling Debugging Scheduling
  481. All the \ref OnlinePerformanceTools and \ref OfflinePerformanceTools can
  482. be used to get information about how well the execution proceeded, and thus the
  483. overall quality of the execution.
  484. Precise debugging can also be performed by using the
  485. \ref STARPU_TASK_BREAK_ON_PUSH, \ref STARPU_TASK_BREAK_ON_SCHED,
  486. \ref STARPU_TASK_BREAK_ON_POP, and \ref STARPU_TASK_BREAK_ON_EXEC environment variables.
  487. By setting the job_id of a task
  488. in these environment variables, StarPU will raise <c>SIGTRAP</c> when the task is being
  489. scheduled, pushed, or popped by the scheduler. This means that when one notices
  490. that a task is being scheduled in a seemingly odd way, one can just reexecute
  491. the application in a debugger, with some of those variables set, and the
  492. execution will stop exactly at the scheduling points of this task, thus allowing
  493. to inspect the scheduler state, etc.
  494. */