350_scheduling_policy_definition.doxy 26 KB

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