350_scheduling_policy_definition.doxy 28 KB

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