350_scheduling_policy_definition.doxy 27 KB

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