starpu_sched_component.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Simon Archipoff
  5. * Copyright (C) 2017 Arthur Chevalier
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_SCHED_COMPONENT_H__
  19. #define __STARPU_SCHED_COMPONENT_H__
  20. #include <starpu.h>
  21. #ifdef STARPU_HAVE_HWLOC
  22. #include <hwloc.h>
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /**
  29. @defgroup API_Modularized_Scheduler Modularized Scheduler Interface
  30. @{
  31. */
  32. /**
  33. flags for starpu_sched_component::properties
  34. */
  35. enum starpu_sched_component_properties
  36. {
  37. /** indicate that all workers have the same starpu_worker_archtype */
  38. STARPU_SCHED_COMPONENT_HOMOGENEOUS = (1<<0),
  39. /** indicate that all workers have the same memory component */
  40. STARPU_SCHED_COMPONENT_SINGLE_MEMORY_NODE = (1<<1)
  41. };
  42. /**
  43. indicate if component is homogeneous
  44. */
  45. #define STARPU_SCHED_COMPONENT_IS_HOMOGENEOUS(component) ((component)->properties & STARPU_SCHED_COMPONENT_HOMOGENEOUS)
  46. /**
  47. indicate if all workers have the same memory component
  48. */
  49. #define STARPU_SCHED_COMPONENT_IS_SINGLE_MEMORY_NODE(component) ((component)->properties & STARPU_SCHED_COMPONENT_SINGLE_MEMORY_NODE)
  50. /**
  51. Structure for a scheduler module. A scheduler is a
  52. tree-like structure of them, some parts of scheduler can be shared by
  53. several contexes to perform some local optimisations, so, for all
  54. components, a list of parent is defined by \c sched_ctx_id. They
  55. embed there specialised method in a pseudo object-style, so calls are
  56. like <c>component->push_task(component,task)</c>
  57. */
  58. struct starpu_sched_component
  59. {
  60. /** The tree containing the component*/
  61. struct starpu_sched_tree *tree;
  62. /** set of underlying workers */
  63. struct starpu_bitmap workers;
  64. /**
  65. subset of starpu_sched_component::workers that is currently available in the context
  66. The push method should take this value into account, it is set with:
  67. component->workers UNION tree->workers UNION
  68. component->child[i]->workers_in_ctx iff exist x such as component->children[i]->parents[x] == component
  69. */
  70. struct starpu_bitmap workers_in_ctx;
  71. /** private data */
  72. void *data;
  73. char *name;
  74. /** number of compoments's children */
  75. unsigned nchildren;
  76. /** vector of component's children */
  77. struct starpu_sched_component **children;
  78. /** number of component's parents */
  79. unsigned nparents;
  80. /** vector of component's parents */
  81. struct starpu_sched_component **parents;
  82. /** add a child to component */
  83. void (*add_child)(struct starpu_sched_component *component, struct starpu_sched_component *child);
  84. /** remove a child from component */
  85. void (*remove_child)(struct starpu_sched_component *component, struct starpu_sched_component *child);
  86. void (*add_parent)(struct starpu_sched_component *component, struct starpu_sched_component *parent);
  87. void (*remove_parent)(struct starpu_sched_component *component, struct starpu_sched_component *parent);
  88. /**
  89. push a task in the scheduler module. this function is called to
  90. push a task on component subtree, this can either perform a
  91. recursive call on a child or store the task in the component,
  92. then it will be returned by a further pull_task call.
  93. the caller must ensure that component is able to execute task.
  94. This method must either return 0 if it the task was properly stored or
  95. passed over to a child component, or return a value different from 0 if the
  96. task could not be consumed (e.g. the queue is full).
  97. */
  98. int (*push_task)(struct starpu_sched_component *, struct starpu_task *);
  99. /**
  100. pop a task from the scheduler module. this function is called by workers to get a task from their
  101. parents. this function should first return a locally stored task
  102. or perform a recursive call on the parents.
  103. the task returned by this function should be executable by the caller
  104. */
  105. struct starpu_task *(*pull_task)(struct starpu_sched_component *from, struct starpu_sched_component *to);
  106. /**
  107. This function is called by a component which implements a queue,
  108. allowing it to signify to its parents that an empty slot is
  109. available in its queue. This should return 1 if some tasks could be pushed
  110. The basic implementation of this function
  111. is a recursive call to its parents, the user has to specify a
  112. personally-made function to catch those calls.
  113. */
  114. int (*can_push)(struct starpu_sched_component *from, struct starpu_sched_component *to);
  115. /**
  116. This function allow a component to wake up a worker. It is
  117. currently called by component which implements a queue, to
  118. signify to its children that a task have been pushed in its local
  119. queue, and is available to be popped by a worker, for example.
  120. This should return 1 if some some container or worker could (or will) pull
  121. some tasks.
  122. The basic implementation of this function is a recursive call to
  123. its children, until at least one worker have been woken up.
  124. */
  125. int (*can_pull)(struct starpu_sched_component *component);
  126. /**
  127. This function is called when starpu_do_schedule() is called by the application.
  128. */
  129. void (*do_schedule)(struct starpu_sched_component *component);
  130. int (*notify)(struct starpu_sched_component* component, int message_ID, void* arg);
  131. /**
  132. heuristic to compute load of scheduler module. Basically the number of tasks divided by the sum
  133. of relatives speedup of workers available in context.
  134. estimated_load(component) = sum(estimated_load(component_children)) + nb_local_tasks / average(relative_speedup(underlying_worker))
  135. */
  136. double (*estimated_load)(struct starpu_sched_component *component);
  137. /**
  138. return the time when a worker will enter in starvation. This function is relevant only if the task->predicted
  139. member has been set.
  140. */
  141. double (*estimated_end)(struct starpu_sched_component *component);
  142. /**
  143. called by starpu_sched_component_destroy. Should free data allocated during creation
  144. */
  145. void (*deinit_data)(struct starpu_sched_component *component);
  146. /**
  147. this function is called for each component when workers are added or removed from a context
  148. */
  149. void (*notify_change_workers)(struct starpu_sched_component *component);
  150. int properties;
  151. #ifdef STARPU_HAVE_HWLOC
  152. /**
  153. the hwloc object associated to scheduler module. points to the
  154. part of topology that is binded to this component, eg: a numa
  155. node for a ws component that would balance load between
  156. underlying sockets
  157. */
  158. hwloc_obj_t obj;
  159. #else
  160. void *obj;
  161. #endif
  162. };
  163. /**
  164. The actual scheduler
  165. */
  166. struct starpu_sched_tree
  167. {
  168. /**
  169. entry module of the scheduler
  170. */
  171. struct starpu_sched_component *root;
  172. /**
  173. set of workers available in this context, this value is used to mask workers in modules
  174. */
  175. struct starpu_bitmap workers;
  176. /**
  177. context id of the scheduler
  178. */
  179. unsigned sched_ctx_id;
  180. /**
  181. lock used to protect the scheduler, it is taken in read mode pushing a task and in write mode for adding or
  182. removing workers
  183. */
  184. starpu_pthread_mutex_t lock;
  185. };
  186. void starpu_initialize_prio_center_policy(unsigned sched_ctx_id);
  187. /**
  188. @name Scheduling Tree API
  189. @{
  190. */
  191. /**
  192. create a empty initialized starpu_sched_tree
  193. */
  194. struct starpu_sched_tree *starpu_sched_tree_create(unsigned sched_ctx_id) STARPU_ATTRIBUTE_MALLOC;
  195. /**
  196. destroy tree and free all non shared component in it.
  197. */
  198. void starpu_sched_tree_destroy(struct starpu_sched_tree *tree);
  199. /**
  200. calls starpu_sched_tree_destroy, ready for use for starpu_sched_policy::deinit_sched field.
  201. */
  202. void starpu_sched_tree_deinitialize(unsigned sched_ctx_id);
  203. struct starpu_sched_tree *starpu_sched_tree_get(unsigned sched_ctx_id);
  204. /**
  205. recursively set all starpu_sched_component::workers, do not take into account shared parts (except workers).
  206. */
  207. void starpu_sched_tree_update_workers(struct starpu_sched_tree *t);
  208. /**
  209. recursively set all starpu_sched_component::workers_in_ctx, do not take into account shared parts (except workers)
  210. */
  211. void starpu_sched_tree_update_workers_in_ctx(struct starpu_sched_tree *t);
  212. /**
  213. compatibility with starpu_sched_policy interface
  214. */
  215. int starpu_sched_tree_push_task(struct starpu_task *task);
  216. /**
  217. compatibility with starpu_sched_policy interface
  218. */
  219. struct starpu_task *starpu_sched_tree_pop_task(unsigned sched_ctx);
  220. /**
  221. Push a task to a component. This is a helper for <c>component->push_task(component, task)</c> plus tracing.
  222. */
  223. int starpu_sched_component_push_task(struct starpu_sched_component *from, struct starpu_sched_component *to, struct starpu_task *task);
  224. /**
  225. Pull a task from a component. This is a helper for <c>component->pull_task(component)</c> plus tracing.
  226. */
  227. struct starpu_task *starpu_sched_component_pull_task(struct starpu_sched_component *from, struct starpu_sched_component *to);
  228. struct starpu_task* starpu_sched_component_pump_to(struct starpu_sched_component *component, struct starpu_sched_component *to, int* success);
  229. struct starpu_task* starpu_sched_component_pump_downstream(struct starpu_sched_component *component, int* success);
  230. int starpu_sched_component_send_can_push_to_parents(struct starpu_sched_component * component);
  231. /**
  232. compatibility with starpu_sched_policy interface
  233. */
  234. void starpu_sched_tree_add_workers(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  235. /**
  236. compatibility with starpu_sched_policy interface
  237. */
  238. void starpu_sched_tree_remove_workers(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  239. /**
  240. Run the do_schedule method of the components. This is a helper for starpu_sched_policy::do_schedule.
  241. */
  242. void starpu_sched_tree_do_schedule(unsigned sched_ctx_id);
  243. /**
  244. Attach component \p child to parent \p parent. Some component may accept only one child, others accept several (e.g. MCT)
  245. */
  246. void starpu_sched_component_connect(struct starpu_sched_component *parent, struct starpu_sched_component *child);
  247. /** @} */
  248. /**
  249. @name Generic Scheduling Component API
  250. @{
  251. */
  252. typedef struct starpu_sched_component * (*starpu_sched_component_create_t)(struct starpu_sched_tree *tree, void *data);
  253. /**
  254. allocate and initialize component field with defaults values :
  255. .pop_task make recursive call on father
  256. .estimated_load compute relative speedup and tasks in sub tree
  257. .estimated_end return the minimum of recursive call on children
  258. .add_child is starpu_sched_component_add_child
  259. .remove_child is starpu_sched_component_remove_child
  260. .notify_change_workers does nothing
  261. .deinit_data does nothing
  262. */
  263. struct starpu_sched_component *starpu_sched_component_create(struct starpu_sched_tree *tree, const char *name) STARPU_ATTRIBUTE_MALLOC;
  264. /**
  265. free data allocated by starpu_sched_component_create and call component->deinit_data(component)
  266. set to <c>NULL</c> the member starpu_sched_component::fathers[sched_ctx_id] of all child if its equal to \p component
  267. */
  268. void starpu_sched_component_destroy(struct starpu_sched_component *component);
  269. /**
  270. recursively destroy non shared parts of a \p component 's tree
  271. */
  272. void starpu_sched_component_destroy_rec(struct starpu_sched_component *component);
  273. void starpu_sched_component_add_child(struct starpu_sched_component* component, struct starpu_sched_component * child);
  274. /**
  275. return true iff \p component can execute \p task, this function take into account the workers available in the scheduling context
  276. */
  277. int starpu_sched_component_can_execute_task(struct starpu_sched_component *component, struct starpu_task *task);
  278. /**
  279. return a non <c>NULL</c> value if \p component can execute \p task.
  280. write the execution prediction length for the best implementation of the best worker available and write this at \p length address.
  281. this result is more relevant if starpu_sched_component::is_homogeneous is non <c>NULL</c>.
  282. if a worker need to be calibrated for an implementation, nan is set to \p length.
  283. */
  284. int STARPU_WARN_UNUSED_RESULT starpu_sched_component_execute_preds(struct starpu_sched_component *component, struct starpu_task *task, double *length);
  285. /**
  286. return the average time to transfer \p task data to underlying \p component workers.
  287. */
  288. double starpu_sched_component_transfer_length(struct starpu_sched_component *component, struct starpu_task *task);
  289. void starpu_sched_component_prefetch_on_node(struct starpu_sched_component *component, struct starpu_task *task);
  290. /** @} */
  291. /**
  292. @name Worker Component API
  293. @{
  294. */
  295. /**
  296. return the struct starpu_sched_component corresponding to \p workerid. Undefined if \p workerid is not a valid workerid
  297. */
  298. struct starpu_sched_component *starpu_sched_component_worker_get(unsigned sched_ctx, int workerid);
  299. struct starpu_sched_component *starpu_sched_component_worker_new(unsigned sched_ctx, int workerid);
  300. /**
  301. Create a combined worker that pushes tasks in parallel to workers \p workers (size \p nworkers).
  302. */
  303. struct starpu_sched_component *starpu_sched_component_parallel_worker_create(struct starpu_sched_tree *tree, unsigned nworkers, unsigned *workers);
  304. /**
  305. return the workerid of \p worker_component, undefined if starpu_sched_component_is_worker(worker_component) == 0
  306. */
  307. int starpu_sched_component_worker_get_workerid(struct starpu_sched_component *worker_component);
  308. /**
  309. return true iff \p component is a worker component
  310. */
  311. int starpu_sched_component_is_worker(struct starpu_sched_component *component);
  312. /**
  313. return true iff \p component is a simple worker component
  314. */
  315. int starpu_sched_component_is_simple_worker(struct starpu_sched_component *component);
  316. /**
  317. return true iff \p component is a combined worker component
  318. */
  319. int starpu_sched_component_is_combined_worker(struct starpu_sched_component *component);
  320. /**
  321. compatibility with starpu_sched_policy interface
  322. update predictions for workers
  323. */
  324. void starpu_sched_component_worker_pre_exec_hook(struct starpu_task *task, unsigned sched_ctx_id);
  325. /**
  326. compatibility with starpu_sched_policy interface
  327. */
  328. void starpu_sched_component_worker_post_exec_hook(struct starpu_task *task, unsigned sched_ctx_id);
  329. /** @} */
  330. /**
  331. @name Flow-control Fifo Component API
  332. @{
  333. */
  334. /**
  335. default function for the pull component method, just call pull of parents until one of them returns a task
  336. */
  337. struct starpu_task * starpu_sched_component_parents_pull_task(struct starpu_sched_component * component, struct starpu_sched_component * to);
  338. /**
  339. default function for the can_push component method, just call can_push of parents until one of them returns non-zero
  340. */
  341. int starpu_sched_component_can_push(struct starpu_sched_component * component, struct starpu_sched_component * to);
  342. /**
  343. default function for the can_pull component method, just call can_pull of children until one of them returns non-zero
  344. */
  345. int starpu_sched_component_can_pull(struct starpu_sched_component * component);
  346. /**
  347. function for the can_pull component method, call can_pull of all children
  348. */
  349. int starpu_sched_component_can_pull_all(struct starpu_sched_component * component);
  350. /**
  351. default function for the estimated_load component method, just sum up the loads
  352. of the children of the component.
  353. */
  354. double starpu_sched_component_estimated_load(struct starpu_sched_component * component);
  355. /**
  356. function that can be used for the estimated_end component method, compute the minimum completion time of the children.
  357. */
  358. double starpu_sched_component_estimated_end_min(struct starpu_sched_component * component);
  359. /**
  360. function that can be used for the estimated_end component method, compute
  361. the minimum completion time of the children, and add to it an estimation of how
  362. existing queued work, plus the exp_len work, can be completed. This is typically
  363. used instead of starpu_sched_component_estimated_end_min when the component
  364. contains a queue of tasks, which thus needs to be added to the estimations.
  365. */
  366. double starpu_sched_component_estimated_end_min_add(struct starpu_sched_component * component, double exp_len);
  367. /**
  368. default function for the estimated_end component method, compute the average completion time of the children.
  369. */
  370. double starpu_sched_component_estimated_end_average(struct starpu_sched_component * component);
  371. struct starpu_sched_component_fifo_data
  372. {
  373. unsigned ntasks_threshold;
  374. double exp_len_threshold;
  375. int ready;
  376. int exp;
  377. };
  378. /**
  379. Return a struct starpu_sched_component with a fifo. A stable sort is performed according to tasks priorities.
  380. A push_task call on this component does not perform recursive calls, underlying components will have to call pop_task to get it.
  381. starpu_sched_component::estimated_end function compute the estimated length by dividing the sequential length by the number of underlying workers.
  382. */
  383. struct starpu_sched_component *starpu_sched_component_fifo_create(struct starpu_sched_tree *tree, struct starpu_sched_component_fifo_data *fifo_data) STARPU_ATTRIBUTE_MALLOC;
  384. /**
  385. return true iff \p component is a fifo component
  386. */
  387. int starpu_sched_component_is_fifo(struct starpu_sched_component *component);
  388. /** @} */
  389. /**
  390. @name Flow-control Prio Component API
  391. @{
  392. */
  393. struct starpu_sched_component_prio_data
  394. {
  395. unsigned ntasks_threshold;
  396. double exp_len_threshold;
  397. int ready;
  398. int exp;
  399. };
  400. struct starpu_sched_component *starpu_sched_component_prio_create(struct starpu_sched_tree *tree, struct starpu_sched_component_prio_data *prio_data) STARPU_ATTRIBUTE_MALLOC;
  401. int starpu_sched_component_is_prio(struct starpu_sched_component *component);
  402. /** @} */
  403. /**
  404. @name Resource-mapping Work-Stealing Component API
  405. @{
  406. */
  407. /**
  408. return a component that perform a work stealing scheduling. Tasks are pushed in a round robin way. estimated_end return the average of expected length of fifos, starting at the average of the expected_end of his children. When a worker have to steal a task, it steal a task in a round robin way, and get the last pushed task of the higher priority.
  409. */
  410. struct starpu_sched_component *starpu_sched_component_work_stealing_create(struct starpu_sched_tree *tree, void *arg) STARPU_ATTRIBUTE_MALLOC;
  411. /**
  412. return true iff \p component is a work stealing component
  413. */
  414. int starpu_sched_component_is_work_stealing(struct starpu_sched_component *component);
  415. /**
  416. undefined if there is no work stealing component in the scheduler. If any, \p task is pushed in a default way if the caller is the application, and in the caller's fifo if its a worker.
  417. */
  418. int starpu_sched_tree_work_stealing_push_task(struct starpu_task *task);
  419. /** @} */
  420. /**
  421. @name Resource-mapping Random Component API
  422. @{
  423. */
  424. /**
  425. create a component that perform a random scheduling
  426. */
  427. struct starpu_sched_component *starpu_sched_component_random_create(struct starpu_sched_tree *tree, void *arg) STARPU_ATTRIBUTE_MALLOC;
  428. /**
  429. return true iff \p component is a random component
  430. */
  431. int starpu_sched_component_is_random(struct starpu_sched_component *);
  432. /** @} */
  433. /**
  434. @name Resource-mapping Eager Component API
  435. @{
  436. */
  437. struct starpu_sched_component *starpu_sched_component_eager_create(struct starpu_sched_tree *tree, void *arg) STARPU_ATTRIBUTE_MALLOC;
  438. int starpu_sched_component_is_eager(struct starpu_sched_component *);
  439. /** @} */
  440. /**
  441. @name Resource-mapping Eager Prio Component API
  442. @{
  443. */
  444. struct starpu_sched_component *starpu_sched_component_eager_prio_create(struct starpu_sched_tree *tree, void *arg) STARPU_ATTRIBUTE_MALLOC;
  445. int starpu_sched_component_is_eager_prio(struct starpu_sched_component *);
  446. /** @} */
  447. /**
  448. @name Resource-mapping Eager-Calibration Component API
  449. @{
  450. */
  451. struct starpu_sched_component *starpu_sched_component_eager_calibration_create(struct starpu_sched_tree *tree, void *arg) STARPU_ATTRIBUTE_MALLOC;
  452. int starpu_sched_component_is_eager_calibration(struct starpu_sched_component *);
  453. /** @} */
  454. /**
  455. @name Resource-mapping MCT Component API
  456. @{
  457. */
  458. struct starpu_sched_component_mct_data
  459. {
  460. double alpha;
  461. double beta;
  462. double _gamma;
  463. double idle_power;
  464. };
  465. /**
  466. create a component with mct_data paremeters. the mct component doesnt
  467. do anything but pushing tasks on no_perf_model_component and
  468. calibrating_component
  469. */
  470. struct starpu_sched_component *starpu_sched_component_mct_create(struct starpu_sched_tree *tree, struct starpu_sched_component_mct_data *mct_data) STARPU_ATTRIBUTE_MALLOC;
  471. int starpu_sched_component_is_mct(struct starpu_sched_component *component);
  472. /** @} */
  473. /**
  474. @name Resource-mapping Heft Component API
  475. @{
  476. */
  477. struct starpu_sched_component *starpu_sched_component_heft_create(struct starpu_sched_tree *tree, struct starpu_sched_component_mct_data *mct_data) STARPU_ATTRIBUTE_MALLOC;
  478. int starpu_sched_component_is_heft(struct starpu_sched_component *component);
  479. /** @} */
  480. /**
  481. @name Resource-mapping Heteroprio Component API
  482. @{
  483. */
  484. struct starpu_sched_component_heteroprio_data
  485. {
  486. struct starpu_sched_component_mct_data *mct;
  487. unsigned batch;
  488. };
  489. struct starpu_sched_component * starpu_sched_component_heteroprio_create(struct starpu_sched_tree *tree, struct starpu_sched_component_heteroprio_data * params) STARPU_ATTRIBUTE_MALLOC;
  490. int starpu_sched_component_is_heteroprio(struct starpu_sched_component *component);
  491. /** @} */
  492. /**
  493. @name Special-purpose Best_Implementation Component API
  494. @{
  495. */
  496. /**
  497. Select the implementation that offer the shortest computation length for the first worker that can execute the task.
  498. Or an implementation that need to be calibrated.
  499. Also set starpu_task::predicted and starpu_task::predicted_transfer for memory component of the first suitable workerid.
  500. If starpu_sched_component::push method is called and starpu_sched_component::nchild > 1 the result is undefined.
  501. */
  502. struct starpu_sched_component *starpu_sched_component_best_implementation_create(struct starpu_sched_tree *tree, void *arg) STARPU_ATTRIBUTE_MALLOC;
  503. /** @} */
  504. /**
  505. @name Special-purpose Perfmodel_Select Component API
  506. @{
  507. */
  508. struct starpu_sched_component_perfmodel_select_data
  509. {
  510. struct starpu_sched_component *calibrator_component;
  511. struct starpu_sched_component *no_perfmodel_component;
  512. struct starpu_sched_component *perfmodel_component;
  513. };
  514. struct starpu_sched_component *starpu_sched_component_perfmodel_select_create(struct starpu_sched_tree *tree, struct starpu_sched_component_perfmodel_select_data *perfmodel_select_data) STARPU_ATTRIBUTE_MALLOC;
  515. int starpu_sched_component_is_perfmodel_select(struct starpu_sched_component *component);
  516. /** @} */
  517. /**
  518. @name Staged pull Component API
  519. @{
  520. */
  521. struct starpu_sched_component * starpu_sched_component_stage_create(struct starpu_sched_tree *tree, void *arg) STARPU_ATTRIBUTE_MALLOC;
  522. int starpu_sched_component_is_stage(struct starpu_sched_component *component);
  523. /** @} */
  524. /**
  525. @name User-choice push Component API
  526. @{
  527. */
  528. struct starpu_sched_component * starpu_sched_component_userchoice_create(struct starpu_sched_tree *tree, void *arg) STARPU_ATTRIBUTE_MALLOC;
  529. int starpu_sched_component_is_userchoice(struct starpu_sched_component *component);
  530. /** @} */
  531. /**
  532. @name Recipe Component API
  533. @{
  534. */
  535. /**
  536. parameters for starpu_sched_component_composed_component_create
  537. */
  538. struct starpu_sched_component_composed_recipe;
  539. /**
  540. return an empty recipe for a composed component, it should not be used without modification
  541. */
  542. struct starpu_sched_component_composed_recipe *starpu_sched_component_composed_recipe_create(void) STARPU_ATTRIBUTE_MALLOC;
  543. /**
  544. return a recipe to build a composed component with a \p create_component
  545. */
  546. struct starpu_sched_component_composed_recipe *starpu_sched_component_composed_recipe_create_singleton(struct starpu_sched_component *(*create_component)(struct starpu_sched_tree *tree, void *arg), void *arg) STARPU_ATTRIBUTE_MALLOC;
  547. /**
  548. add \p create_component under all previous components in recipe
  549. */
  550. void starpu_sched_component_composed_recipe_add(struct starpu_sched_component_composed_recipe *recipe, struct starpu_sched_component *(*create_component)(struct starpu_sched_tree *tree, void *arg), void *arg);
  551. /**
  552. destroy composed_sched_component, this should be done after starpu_sched_component_composed_component_create was called
  553. */
  554. void starpu_sched_component_composed_recipe_destroy(struct starpu_sched_component_composed_recipe *);
  555. /**
  556. create a component that behave as all component of recipe where linked. Except that you cant use starpu_sched_component_is_foo function
  557. if recipe contain a single create_foo arg_foo pair, create_foo(arg_foo) is returned instead of a composed component
  558. */
  559. struct starpu_sched_component *starpu_sched_component_composed_component_create(struct starpu_sched_tree *tree, struct starpu_sched_component_composed_recipe *recipe) STARPU_ATTRIBUTE_MALLOC;
  560. #ifdef STARPU_HAVE_HWLOC
  561. /**
  562. Define how build a scheduler according to topology. Each level (except for hwloc_machine_composed_sched_component) can be <c>NULL</c>, then
  563. the level is just skipped. Bugs everywhere, do not rely on.
  564. */
  565. struct starpu_sched_component_specs
  566. {
  567. /**
  568. the composed component to put on the top of the scheduler
  569. this member must not be <c>NULL</c> as it is the root of the topology
  570. */
  571. struct starpu_sched_component_composed_recipe *hwloc_machine_composed_sched_component;
  572. /**
  573. the composed component to put for each memory component
  574. */
  575. struct starpu_sched_component_composed_recipe *hwloc_component_composed_sched_component;
  576. /**
  577. the composed component to put for each socket
  578. */
  579. struct starpu_sched_component_composed_recipe *hwloc_socket_composed_sched_component;
  580. /**
  581. the composed component to put for each cache
  582. */
  583. struct starpu_sched_component_composed_recipe *hwloc_cache_composed_sched_component;
  584. /**
  585. a function that return a starpu_sched_component_composed_recipe to put on top of a worker of type \p archtype.
  586. <c>NULL</c> is a valid return value, then no component will be added on top
  587. */
  588. struct starpu_sched_component_composed_recipe *(*worker_composed_sched_component)(enum starpu_worker_archtype archtype);
  589. /**
  590. this flag is a dirty hack because of the poor expressivity of this interface. As example, if you want to build
  591. a heft component with a fifo component per numa component, and you also have GPUs, if this flag is set, GPUs will share those fifos.
  592. If this flag is not set, a new fifo will be built for each of them (if they have the same starpu_perf_arch and the same
  593. numa component it will be shared. it indicates if heterogenous workers should be brothers or cousins, as example, if a gpu and a cpu should share or not there numa node
  594. */
  595. int mix_heterogeneous_workers;
  596. };
  597. /**
  598. build a scheduler for \p sched_ctx_id according to \p s and the hwloc topology of the machine.
  599. */
  600. struct starpu_sched_tree *starpu_sched_component_make_scheduler(unsigned sched_ctx_id, struct starpu_sched_component_specs s);
  601. #endif /* STARPU_HAVE_HWLOC */
  602. /**
  603. @name Basic API
  604. @{
  605. */
  606. #define STARPU_SCHED_SIMPLE_DECIDE_MASK (3<<0)
  607. /**
  608. Request to create downstream queues per worker, i.e. the scheduling decision-making component will choose exactly which workers tasks should got to.
  609. */
  610. #define STARPU_SCHED_SIMPLE_DECIDE_WORKERS (1<<0)
  611. /**
  612. Request to create downstream queues per memory nodes, i.e. the scheduling decision-making component will choose which memory node tasks will go to.
  613. */
  614. #define STARPU_SCHED_SIMPLE_DECIDE_MEMNODES (2<<0)
  615. /**
  616. Request to create downstream queues per computation arch, i.e. the scheduling decision-making component will choose whether tasks go to CPUs, or CUDA, or OpenCL, etc.
  617. */
  618. #define STARPU_SCHED_SIMPLE_DECIDE_ARCHS (3<<0)
  619. /**
  620. Request to create the scheduling decision-making component even if there is only one available choice. This is useful for instance when the decision-making component will store tasks itself (and not use STARPU_SCHED_SIMPLE_FIFO_ABOVE) to decide in which order tasks should be passed below.
  621. */
  622. #define STARPU_SCHED_SIMPLE_DECIDE_ALWAYS (1<<3)
  623. /**
  624. Request to add a perfmodel selector above the scheduling decision-making component. That way, only tasks with a calibrated performance model will be given to the component, other tasks will go to an eager branch that will distributed tasks so that their performance models will get calibrated.
  625. In other words, this is needed when using a component which needs performance models for tasks.
  626. */
  627. #define STARPU_SCHED_SIMPLE_PERFMODEL (1<<4)
  628. /**
  629. Request that a component be added just above workers, that chooses the best task implementation.
  630. */
  631. #define STARPU_SCHED_SIMPLE_IMPL (1<<5)
  632. /**
  633. Request to create a fifo above the scheduling decision-making component, otherwise tasks will be pushed directly to the component.
  634. This is useful to store tasks if there is a fifo below which limits the number of tasks to be scheduld in advance. The scheduling decision-making component can also store tasks itself, in which case this flag is not useful.
  635. */
  636. #define STARPU_SCHED_SIMPLE_FIFO_ABOVE (1<<6)
  637. /**
  638. Request that the fifo above be sorted by priorities
  639. */
  640. #define STARPU_SCHED_SIMPLE_FIFO_ABOVE_PRIO (1<<7)
  641. /**
  642. Request to create fifos below the scheduling decision-making component, otherwise tasks will be pulled directly from workers.
  643. This is useful to be able to schedule a (tunable) small number of tasks in advance only.
  644. */
  645. #define STARPU_SCHED_SIMPLE_FIFOS_BELOW (1<<8)
  646. /**
  647. Request that the fifos below be sorted by priorities
  648. */
  649. #define STARPU_SCHED_SIMPLE_FIFOS_BELOW_PRIO (1<<9)
  650. /**
  651. Request that the fifos below be pulled rather ready tasks
  652. */
  653. #define STARPU_SCHED_SIMPLE_FIFOS_BELOW_READY (1<<10)
  654. /**
  655. Request that work between workers using the same fifo below be distributed using a work stealing component.
  656. */
  657. #define STARPU_SCHED_SIMPLE_WS_BELOW (1<<11)
  658. /**
  659. Request to not only choose between simple workers, but also choose between combined workers.
  660. */
  661. #define STARPU_SCHED_SIMPLE_COMBINED_WORKERS (1<<12)
  662. /**
  663. Request that the fifos below keep track of expected duration, start and end time of theirs elements
  664. */
  665. #define STARPU_SCHED_SIMPLE_FIFOS_BELOW_EXP (1<<13)
  666. /**
  667. Request to prepend a component before the decision component. This should be
  668. used alone and followed by the component creation function pointer and its
  669. data.
  670. */
  671. #define STARPU_SCHED_SIMPLE_PRE_DECISION (1<<14)
  672. /**
  673. Create a simple modular scheduler tree around a scheduling decision-making
  674. component \p component. The details of what should be built around \p component
  675. is described by \p flags. The different STARPU_SCHED_SIMPL_DECIDE_* flags are
  676. mutually exclusive. \p data is passed to the \p create_decision_component
  677. function when creating the decision component.
  678. */
  679. void starpu_sched_component_initialize_simple_scheduler(starpu_sched_component_create_t create_decision_component, void *data, unsigned flags, unsigned sched_ctx_id);
  680. /**
  681. Create a simple modular scheduler tree around several scheduling decision-making
  682. components. The parameters are similar to
  683. starpu_sched_component_initialize_simple_scheduler, but per scheduling decision, for instance:
  684. starpu_sched_component_initialize_simple_schedulers(sched_ctx_id, 2,
  685. create1, data1, flags1,
  686. create2, data2, flags2);
  687. The different flags parameters must be coherent: same decision flags. They
  688. must not include the perfmodel flag (not supported yet).
  689. */
  690. void starpu_sched_component_initialize_simple_schedulers(unsigned sched_ctx_id, unsigned ndecisions, ...);
  691. /** @} */
  692. #define STARPU_COMPONENT_MUTEX_LOCK(m) \
  693. do \
  694. { \
  695. const int _relaxed_state = starpu_worker_get_relax_state(); \
  696. if (!_relaxed_state) \
  697. starpu_worker_relax_on(); \
  698. STARPU_PTHREAD_MUTEX_LOCK((m)); \
  699. if (!_relaxed_state) \
  700. starpu_worker_relax_off(); \
  701. } \
  702. while(0)
  703. #define STARPU_COMPONENT_MUTEX_TRYLOCK(m) STARPU_PTHREAD_MUTEX_TRYLOCK((m))
  704. #define STARPU_COMPONENT_MUTEX_UNLOCK(m) STARPU_PTHREAD_MUTEX_UNLOCK((m))
  705. /** @} */
  706. #ifdef __cplusplus
  707. }
  708. #endif
  709. #endif /* __STARPU_SCHED_COMPONENT_H__ */