starpu_sched_node.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #ifndef __SCHED_NODE_H__
  2. #define __SCHED_NODE_H__
  3. #include <starpu.h>
  4. #include <common/starpu_spinlock.h>
  5. #ifdef STARPU_HAVE_HWLOC
  6. #include <hwloc.h>
  7. #endif
  8. /* struct starpu_sched_node are scheduler modules, a scheduler is a tree-like
  9. * structure of them, some parts of scheduler can be shared by several contexes
  10. * to perform some local optimisations, so, for all nodes, a list of father is
  11. * defined indexed by sched_ctx_id
  12. *
  13. * they embed there specialised method in a pseudo object-style, so calls are like node->push_task(node,task)
  14. *
  15. */
  16. struct starpu_sched_node
  17. {
  18. /* node->push_task(node, task)
  19. * this function is called to push a task on node subtree, this can either
  20. * perform a recursive call on a child or store the task in the node, then
  21. * it will be returned by a further pop_task call
  22. *
  23. * the caller must ensure that node is able to execute task
  24. */
  25. int (*push_task)(struct starpu_sched_node *,
  26. struct starpu_task *);
  27. /* this function is called by workers to get a task on them fathers
  28. * this function should first return a localy stored task or perform
  29. * a recursive call on father
  30. *
  31. * a default implementation simply do a recursive call on father
  32. */
  33. struct starpu_task * (*pop_task)(struct starpu_sched_node *,
  34. unsigned sched_ctx_id);
  35. /* this function notify underlying worker that a task as been pushed
  36. * and would be returned by a pop_task call
  37. * it should be called each time a node localy store a task
  38. *
  39. * default implementation simply perform a recursive call on childrens
  40. * this function can be called by a worker as it doesn't try to wake up himself
  41. */
  42. void (*available)(struct starpu_sched_node *);
  43. /* this function is an heuristic that compute load of subtree, basicaly
  44. * it compute
  45. * estimated_load(node) = sum(estimated_load(node_childs)) +
  46. * nb_local_tasks / average(relative_speedup(underlying_worker))
  47. */
  48. double (*estimated_load)(struct starpu_sched_node * node);
  49. /* this function return a struct starpu_task_execute_preds defined lower
  50. * wich basicaly give predictions for a task execution a call on
  51. * homogeneous (with all workers of the same arch) node is optimised
  52. */
  53. struct starpu_task_execute_preds (*estimated_execute_preds)(struct starpu_sched_node * node,
  54. struct starpu_task * task);
  55. /* the numbers of node's childs
  56. */
  57. int nchilds;
  58. /* the vector of node's childs
  59. */
  60. struct starpu_sched_node ** childs;
  61. /* may be shared by several contexts
  62. * so we need several fathers
  63. */
  64. struct starpu_sched_node * fathers[STARPU_NMAX_SCHED_CTXS];
  65. /* the set of workers in the node's subtree
  66. */
  67. struct starpu_bitmap * workers;
  68. /* is_homogeneous is 0 iff workers in the node's subtree are heterogeneous,
  69. * this field is set and updated automaticaly, you shouldn't write on it
  70. */
  71. int is_homogeneous;
  72. /* node's private data, no restriction on use
  73. */
  74. void * data;
  75. /* this function is called after all childs has been set, and the
  76. * workers member was filled, can be used to init data, or anything you want
  77. */
  78. void (*init_data)(struct starpu_sched_node *);
  79. /* this function is called to free data allocated by init_data
  80. * just before the call of starpu_sched_node_destroy(node)
  81. */
  82. void (*deinit_data)(struct starpu_sched_node *);
  83. #ifdef STARPU_HAVE_HWLOC
  84. /* in case of a hierarchical scheduler, this is set to the part of
  85. * topology that is binded to this node, eg: a numa node for a ws
  86. * node that would balance load between underlying sockets
  87. */
  88. hwloc_obj_t obj;
  89. #endif
  90. };
  91. /* this structure is only returned by estimated_execute_preds and give
  92. * predictions on task computations
  93. */
  94. struct starpu_task_execute_preds
  95. {
  96. /* if several value are possible for state member,
  97. * in order of priority :
  98. * CALIBRATING, PERF_MODEL, NO_PERF_MODEL, CANNOT_EXECUTE
  99. */
  100. enum {CANNOT_EXECUTE = 0, CALIBRATING , NO_PERF_MODEL, PERF_MODEL} state;
  101. /* archtype and nimpl is set to
  102. * best values if state is PERF_MODEL
  103. * values that needs to be calibrated if state is CALIBRATING
  104. * suitable values if NO_PERF_MODEL
  105. * irrevelant if CANNOT_EXECUTE
  106. */
  107. enum starpu_perfmodel_archtype archtype;
  108. int impl;
  109. double expected_finish_time;
  110. double expected_length;
  111. double expected_transfer_length;
  112. double expected_power;
  113. };
  114. struct starpu_sched_tree
  115. {
  116. struct starpu_sched_node * root;
  117. struct starpu_bitmap * workers;
  118. /* this lock is used to protect the scheduler,
  119. * it is taken in read mode pushing a task
  120. * and in write mode for adding or removing workers
  121. */
  122. starpu_pthread_rwlock_t lock;
  123. };
  124. struct starpu_sched_node * starpu_sched_node_create(void);
  125. void starpu_sched_node_destroy(struct starpu_sched_node * node);
  126. void starpu_sched_node_set_father(struct starpu_sched_node *node, struct starpu_sched_node *father_node, unsigned sched_ctx_id);
  127. void starpu_sched_node_add_child(struct starpu_sched_node * node, struct starpu_sched_node * child);
  128. void starpu_sched_node_remove_child(struct starpu_sched_node * node, struct starpu_sched_node * child);
  129. struct starpu_task_execute_preds starpu_sched_node_average_estimated_execute_preds(struct starpu_sched_node * node, struct starpu_task * task);
  130. int starpu_sched_node_can_execute_task(struct starpu_sched_node * node, struct starpu_task * task);
  131. int starpu_sched_node_can_execute_task_with_impl(struct starpu_sched_node * node, struct starpu_task * task, unsigned nimpl);
  132. /* no public create function for workers because we dont want to have several node_worker for a single workerid */
  133. struct starpu_sched_node * starpu_sched_node_worker_get(int workerid);
  134. struct _starpu_worker * starpu_sched_node_worker_get_worker(struct starpu_sched_node * worker_node);
  135. struct _starpu_combined_worker * starpu_sched_node_combined_worker_get_combined_worker(struct starpu_sched_node * combined_worker_node);
  136. void starpu_sched_node_worker_destroy(struct starpu_sched_node *);
  137. /* this function compare the available function of the node with the standard available for worker nodes*/
  138. int starpu_sched_node_is_worker(struct starpu_sched_node * node);
  139. int starpu_sched_node_is_simple_worker(struct starpu_sched_node * node);
  140. int starpu_sched_node_is_combined_worker(struct starpu_sched_node * node);
  141. int starpu_sched_node_worker_get_workerid(struct starpu_sched_node * worker_node);
  142. struct starpu_sched_node * starpu_sched_node_fifo_create(void * arg STARPU_ATTRIBUTE_UNUSED);
  143. int starpu_sched_node_is_fifo(struct starpu_sched_node * node);
  144. //struct starpu_task_list starpu_sched_node_fifo_get_non_executable_tasks(struct starpu_sched_node * fifo_node);
  145. struct starpu_sched_node * starpu_sched_node_work_stealing_create(void);
  146. int starpu_sched_node_is_work_stealing(struct starpu_sched_node * node);
  147. struct starpu_sched_node * starpu_sched_node_random_create(void * arg STARPU_ATTRIBUTE_UNUSED);
  148. int starpu_sched_node_is_random(struct starpu_sched_node *);
  149. struct starpu_sched_node * starpu_sched_node_eager_create(void * arg STARPU_ATTRIBUTE_UNUSED);
  150. struct starpu_sched_node * starpu_sched_node_heft_create(void * arg STARPU_ATTRIBUTE_UNUSED);
  151. /* this function is called to create the node wich will be used to push task when no perf model are available
  152. * by default, a random node is created
  153. */
  154. void starpu_sched_node_heft_set_no_model_node(struct starpu_sched_node * heft_node,
  155. struct starpu_sched_node * (*create_no_model_node)(void * arg), void * arg);
  156. int starpu_sched_node_is_heft(struct starpu_sched_node * node);
  157. /* compute predicted_end by taking in account the case of the predicted transfer and the predicted_end overlap
  158. */
  159. double starpu_sched_compute_expected_time(double now, double predicted_end, double predicted_length, double predicted_transfer);
  160. /*create an empty tree
  161. */
  162. struct starpu_sched_tree * starpu_sched_tree_create(void);
  163. void starpu_sched_tree_destroy(struct starpu_sched_tree * tree, unsigned sched_ctx_id);
  164. /* destroy node and all his child
  165. * except if they are shared between several contexts
  166. */
  167. void starpu_sched_node_destroy_rec(struct starpu_sched_node * node, unsigned sched_ctx_id);
  168. int starpu_sched_tree_push_task(struct starpu_task * task);
  169. struct starpu_task * starpu_sched_tree_pop_task(unsigned sched_ctx_id);
  170. void starpu_sched_tree_add_workers(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  171. void starpu_sched_tree_remove_workers(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  172. void starpu_sched_node_worker_pre_exec_hook(struct starpu_task * task);
  173. void starpu_sched_node_worker_post_exec_hook(struct starpu_task * task);
  174. /* return the bitmap of worker that are allowed to use in this scheduling context
  175. */
  176. struct starpu_bitmap * _starpu_get_worker_mask(struct starpu_task * task);
  177. /* this function fill all the node->workers members
  178. */
  179. void _starpu_set_workers_bitmaps(void);
  180. /* this function call init data on all nodes in postfix order
  181. */
  182. void starpu_sched_tree_call_init_data(struct starpu_sched_tree * t);
  183. /* push task of list lower as possible in the tree, a non null value is returned if some task couldn't be pushed
  184. */
  185. int starpu_sched_node_push_tasks_to_firsts_suitable_parent(struct starpu_sched_node * node, struct starpu_task_list * list, int sched_ctx_id);
  186. struct starpu_bitmap;
  187. struct starpu_bitmap * starpu_bitmap_create(void);
  188. void starpu_bitmap_destroy(struct starpu_bitmap *);
  189. void starpu_bitmap_set(struct starpu_bitmap *, int);
  190. void starpu_bitmap_unset(struct starpu_bitmap *, int);
  191. void starpu_bitmap_unset_all(struct starpu_bitmap *);
  192. int starpu_bitmap_get(struct starpu_bitmap *, int);
  193. //this is basically compute a |= b;
  194. void starpu_bitmap_or(struct starpu_bitmap * a,
  195. struct starpu_bitmap * b);
  196. //return 1 iff e set in b1 AND e set in b2
  197. int starpu_bitmap_and_get(struct starpu_bitmap * b1,
  198. struct starpu_bitmap * b2,
  199. int e);
  200. int starpu_bitmap_cardinal(struct starpu_bitmap *);
  201. //return the index of first bit, -1 if none
  202. int starpu_bitmap_first(struct starpu_bitmap *);
  203. int starpu_bitmap_last(struct starpu_bitmap *);
  204. //return the index of bit right after e, -1 if none
  205. int starpu_bitmap_next(struct starpu_bitmap *, int e);
  206. #endif