starpu_sched_node.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #ifndef __STARPU_SCHED_NODE_H__
  2. #define __STARPU_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 is an heuristic that compute load of subtree, basicaly
  36. * it compute
  37. * estimated_load(node) = sum(estimated_load(node_childs)) +
  38. * nb_local_tasks / average(relative_speedup(underlying_worker))
  39. */
  40. double (*estimated_load)(struct starpu_sched_node * node);
  41. double (*estimated_end)(struct starpu_sched_node * node);
  42. /* the numbers of node's childs
  43. */
  44. int nchilds;
  45. /* the vector of node's childs
  46. */
  47. struct starpu_sched_node ** childs;
  48. /* may be shared by several contexts
  49. * so we need several fathers
  50. */
  51. struct starpu_sched_node * fathers[STARPU_NMAX_SCHED_CTXS];
  52. /* the set of workers in the node's subtree
  53. */
  54. struct starpu_bitmap * workers;
  55. /* the workers available in context
  56. * this member is set with :
  57. * node->workers UNION tree->workers UNION
  58. * node->child[i]->workers_in_ctx iff exist x such as node->childs[i]->fathers[x] == node
  59. */
  60. struct starpu_bitmap * workers_in_ctx;
  61. /* node's private data, no restriction on use
  62. */
  63. void * data;
  64. void (*add_child)(struct starpu_sched_node * node, struct starpu_sched_node * child);
  65. void (*remove_child)(struct starpu_sched_node * node, struct starpu_sched_node * child);
  66. /* this function is called for each node when workers are added or removed from a context
  67. */
  68. void (*notify_change_workers)(struct starpu_sched_node * node);
  69. /* this function is called by starpu_sched_node_destroy just before freeing node
  70. */
  71. void (*deinit_data)(struct starpu_sched_node * node);
  72. /* is_homogeneous is 0 iff workers in the node's subtree are heterogeneous,
  73. * this field is set and updated automaticaly, you shouldn't write on it
  74. */
  75. int properties;
  76. #ifdef STARPU_HAVE_HWLOC
  77. /* in case of a hierarchical scheduler, this is set to the part of
  78. * topology that is binded to this node, eg: a numa node for a ws
  79. * node that would balance load between underlying sockets
  80. */
  81. hwloc_obj_t obj;
  82. #endif
  83. };
  84. enum starpu_sched_node_properties
  85. {
  86. STARPU_SCHED_NODE_HOMOGENEOUS = (1<<0),
  87. STARPU_SCHED_NODE_SINGLE_MEMORY_NODE = (1<<1)
  88. };
  89. #define STARPU_SCHED_NODE_IS_HOMOGENEOUS(node) ((node)->properties & STARPU_SCHED_NODE_HOMOGENEOUS)
  90. #define STARPU_SCHED_NODE_IS_SINGLE_MEMORY_NODE(node) ((node)->properties & STARPU_SCHED_NODE_SINGLE_MEMORY_NODE)
  91. struct starpu_sched_tree
  92. {
  93. struct starpu_sched_node * root;
  94. struct starpu_bitmap * workers;
  95. unsigned sched_ctx_id;
  96. /* this lock is used to protect the scheduler,
  97. * it is taken in read mode pushing a task
  98. * and in write mode for adding or removing workers
  99. */
  100. starpu_pthread_mutex_t lock;
  101. };
  102. struct starpu_sched_node * starpu_sched_node_create(void);
  103. void starpu_sched_node_destroy(struct starpu_sched_node * node);
  104. void starpu_sched_node_set_father(struct starpu_sched_node *node, struct starpu_sched_node *father_node, unsigned sched_ctx_id);
  105. void starpu_sched_node_add_child(struct starpu_sched_node * node, struct starpu_sched_node * child);
  106. void starpu_sched_node_remove_child(struct starpu_sched_node * node, struct starpu_sched_node * child);
  107. int starpu_sched_node_can_execute_task(struct starpu_sched_node * node, struct starpu_task * task);
  108. int STARPU_WARN_UNUSED_RESULT starpu_sched_node_execute_preds(struct starpu_sched_node * node, struct starpu_task * task, double * length);
  109. double starpu_sched_node_transfer_length(struct starpu_sched_node * node, struct starpu_task * task);
  110. /* no public create function for workers because we dont want to have several node_worker for a single workerid */
  111. struct starpu_sched_node * starpu_sched_node_worker_get(int workerid);
  112. /* this function compare the available function of the node with the standard available for worker nodes*/
  113. int starpu_sched_node_is_worker(struct starpu_sched_node * node);
  114. int starpu_sched_node_is_simple_worker(struct starpu_sched_node * node);
  115. int starpu_sched_node_is_combined_worker(struct starpu_sched_node * node);
  116. int starpu_sched_node_worker_get_workerid(struct starpu_sched_node * worker_node);
  117. struct starpu_sched_node * starpu_sched_node_fifo_create(void * arg STARPU_ATTRIBUTE_UNUSED);
  118. int starpu_sched_node_is_fifo(struct starpu_sched_node * node);
  119. struct starpu_sched_node * starpu_sched_node_work_stealing_create(void * arg STARPU_ATTRIBUTE_UNUSED);
  120. int starpu_sched_node_is_work_stealing(struct starpu_sched_node * node);
  121. int starpu_sched_tree_work_stealing_push_task(struct starpu_task *task);
  122. struct starpu_sched_node * starpu_sched_node_random_create(void * arg STARPU_ATTRIBUTE_UNUSED);
  123. int starpu_sched_node_is_random(struct starpu_sched_node *);
  124. struct starpu_heft_data
  125. {
  126. double alpha;
  127. double beta;
  128. double gamma;
  129. double idle_power;
  130. struct starpu_sched_node * (*no_perf_model_node_create)(void * arg_no_perf_model);
  131. void * arg_no_perf_model;
  132. struct starpu_sched_node * (*calibrating_node_create)(void * arg_calibrating_node);
  133. void * arg_calibrating_node;
  134. };
  135. /* create a node with heft_data paremeters
  136. a copy the struct starpu_heft_data * given is performed during the init_data call
  137. the heft node doesnt do anything but pushing tasks on no_perf_model_node and calibrating_node
  138. */
  139. struct starpu_sched_node * starpu_sched_node_heft_create(struct starpu_heft_data * heft_data);
  140. int starpu_sched_node_is_heft(struct starpu_sched_node * node);
  141. /* this node select the best implementation for the first worker in context that can execute task.
  142. * and fill task->predicted and task->predicted_transfer
  143. * cannot have several childs if push_task is called
  144. */
  145. struct starpu_sched_node * starpu_sched_node_best_implementation_create(void * arg STARPU_ATTRIBUTE_UNUSED);
  146. /*create an empty tree
  147. */
  148. struct starpu_sched_tree * starpu_sched_tree_create(unsigned sched_ctx_id);
  149. void starpu_sched_tree_destroy(struct starpu_sched_tree * tree);
  150. /* destroy node and all his child
  151. * except if they are shared between several contexts
  152. */
  153. void starpu_sched_node_destroy_rec(struct starpu_sched_node * node, unsigned sched_ctx_id);
  154. /* update all the node->workers member recursively
  155. */
  156. void starpu_sched_tree_update_workers(struct starpu_sched_tree * t);
  157. /* idem for workers_in_ctx
  158. */
  159. void starpu_sched_tree_update_workers_in_ctx(struct starpu_sched_tree * t);
  160. /* wake up underlaying workers of node
  161. */
  162. void starpu_sched_node_available(struct starpu_sched_node * node);
  163. int starpu_sched_tree_push_task(struct starpu_task * task);
  164. struct starpu_task * starpu_sched_tree_pop_task(unsigned sched_ctx_id);
  165. void starpu_sched_tree_add_workers(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  166. void starpu_sched_tree_remove_workers(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  167. void starpu_sched_node_worker_pre_exec_hook(struct starpu_task * task);
  168. void starpu_sched_node_worker_post_exec_hook(struct starpu_task * task);
  169. struct starpu_bitmap * starpu_bitmap_create(void);
  170. void starpu_bitmap_destroy(struct starpu_bitmap *);
  171. void starpu_bitmap_set(struct starpu_bitmap *, int);
  172. void starpu_bitmap_unset(struct starpu_bitmap *, int);
  173. void starpu_bitmap_unset_all(struct starpu_bitmap *);
  174. int starpu_bitmap_get(struct starpu_bitmap *, int);
  175. /* basicaly compute starpu_bitmap_unset_all(a) ; a = b & c; */
  176. void starpu_bitmap_unset_and(struct starpu_bitmap * a, struct starpu_bitmap * b, struct starpu_bitmap * c);
  177. /* this is basically compute a |= b;*/
  178. void starpu_bitmap_or(struct starpu_bitmap * a,
  179. struct starpu_bitmap * b);
  180. //return 1 iff e set in b1 AND e set in b2
  181. int starpu_bitmap_and_get(struct starpu_bitmap * b1,
  182. struct starpu_bitmap * b2,
  183. int e);
  184. int starpu_bitmap_cardinal(struct starpu_bitmap *);
  185. //return the index of first bit, -1 if none
  186. int starpu_bitmap_first(struct starpu_bitmap *);
  187. int starpu_bitmap_last(struct starpu_bitmap *);
  188. //return the index of bit right after e, -1 if none
  189. int starpu_bitmap_next(struct starpu_bitmap *, int e);
  190. struct starpu_sched_node_composed_recipe;
  191. /* create empty recipe */
  192. struct starpu_sched_node_composed_recipe * starpu_sched_node_create_recipe(void);
  193. struct starpu_sched_node_composed_recipe * starpu_sched_node_create_recipe_singleton(struct starpu_sched_node *(*create_node)(void * arg), void * arg);
  194. /* add a function creation node to recipe */
  195. void starpu_sched_recipe_add_node(struct starpu_sched_node_composed_recipe * recipe, struct starpu_sched_node *(*create_node)(void * arg), void * arg);
  196. void starpu_destroy_composed_sched_node_recipe(struct starpu_sched_node_composed_recipe *);
  197. struct starpu_sched_node * starpu_sched_node_composed_node_create(struct starpu_sched_node_composed_recipe * recipe);
  198. #ifdef STARPU_HAVE_HWLOC
  199. /* null pointer mean to ignore a level L of hierarchy, then nodes of levels > L become childs of level L - 1 */
  200. struct starpu_sched_specs
  201. {
  202. /* hw_loc_machine_composed_sched_node must be set as its the root of the topology */
  203. struct starpu_sched_node_composed_recipe * hwloc_machine_composed_sched_node;
  204. struct starpu_sched_node_composed_recipe * hwloc_node_composed_sched_node;
  205. struct starpu_sched_node_composed_recipe * hwloc_socket_composed_sched_node;
  206. struct starpu_sched_node_composed_recipe * hwloc_cache_composed_sched_node;
  207. /* this member should return a new allocated starpu_sched_node_composed_recipe or NULL
  208. * the starpu_sched_node_composed_recipe_t must not include the worker node
  209. */
  210. struct starpu_sched_node_composed_recipe * (*worker_composed_sched_node)(enum starpu_worker_archtype archtype);
  211. /* this flag indicate if heterogenous workers should be brothers or cousins,
  212. * as example, if a gpu and a cpu should share or not there numa node
  213. */
  214. int mix_heterogeneous_workers;
  215. };
  216. struct starpu_sched_tree * starpu_sched_node_make_scheduler(unsigned sched_ctx_id, struct starpu_sched_specs);
  217. #endif /* STARPU_HAVE_HWLOC */
  218. #endif