node_sched.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef __SCHED_NODE_H__
  2. #define __SCHED_NODE_H__
  3. #include <starpu.h>
  4. struct _starpu_sched_node
  5. {
  6. int (*push_task)(struct _starpu_sched_node *, struct starpu_task *);
  7. struct starpu_task * (*pop_task)(struct _starpu_sched_node *, unsigned sched_ctx_id);
  8. void (*available)(struct _starpu_sched_node *);
  9. void * data;
  10. int nchilds;
  11. struct _starpu_sched_node ** childs;
  12. starpu_pthread_mutex_t mutex;
  13. //the list of workers in the node's subtree
  14. int workerids[STARPU_NMAXWORKERS];
  15. int nworkers;
  16. /* may be shared by several contexts
  17. * so we need several fathers
  18. */
  19. struct _starpu_sched_node * fathers[STARPU_NMAX_SCHED_CTXS];
  20. void (*add_child)(struct _starpu_sched_node *node,
  21. struct _starpu_sched_node *child,
  22. unsigned sched_ctx_id);
  23. void (*remove_child)(struct _starpu_sched_node *node,
  24. struct _starpu_sched_node *child,
  25. unsigned sched_ctx_id);
  26. /* this function is called to free node (it must call _starpu_sched_node_destroy(node));
  27. */
  28. void (*destroy_node)(struct _starpu_sched_node *);
  29. };
  30. struct _starpu_sched_tree
  31. {
  32. struct _starpu_sched_node * root;
  33. starpu_pthread_mutex_t mutex;
  34. };
  35. /* allocate and initalise node field with defaults values :
  36. * .pop_task return NULL
  37. * .available make a recursive call on childrens
  38. * .destroy_node call _starpu_sched_node_destroy
  39. * .update_nchilds a function that does nothing
  40. * .{add,remove}_child functions that simply add/remove the child and update the .fathers field of child
  41. */
  42. struct _starpu_sched_node * _starpu_sched_node_create(void);
  43. /* free memory allocated by _starpu_sched_node_create, it does not call node->destroy_node(node)*/
  44. void _starpu_sched_node_destroy(struct _starpu_sched_node * node);
  45. void _starpu_sched_node_set_father(struct _starpu_sched_node *node, struct _starpu_sched_node *father_node, unsigned sched_ctx_id);
  46. /* those two function call node->update_nchilds after the child was added or removed */
  47. void _starpu_sched_node_add_child(struct _starpu_sched_node* node, struct _starpu_sched_node * child, unsigned sched_ctx_id);
  48. void _starpu_sched_node_remove_child(struct _starpu_sched_node * node, struct _starpu_sched_node * child, unsigned sched_ctx_id);
  49. int _starpu_sched_node_can_execute_task(struct _starpu_sched_node * node, struct starpu_task * task);
  50. //no public create function for workers because we dont want to have several node_worker for a single workerid
  51. struct _starpu_sched_node * _starpu_sched_node_worker_get(int workerid);
  52. void _starpu_sched_node_worker_destroy(struct _starpu_sched_node *);
  53. /*this function assume that workers are the only leafs */
  54. int _starpu_sched_node_is_worker(struct _starpu_sched_node * node);
  55. int _starpu_sched_node_worker_get_workerid(struct _starpu_sched_node * worker_node);
  56. struct _starpu_sched_node * _starpu_sched_node_fifo_create(void);
  57. struct _starpu_fifo_taskq * _starpu_sched_node_fifo_get_fifo(struct _starpu_sched_node *);
  58. //struct _starpu_sched_node * _starpu_sched_node_work_stealing_create(void);
  59. struct _starpu_sched_node * _starpu_sched_node_random_create(void);
  60. struct _starpu_sched_node * _starpu_sched_node_eager_create(void);
  61. void _starpu_tree_destroy(struct _starpu_sched_tree * tree, unsigned sched_ctx_id);
  62. /* destroy node and all his child
  63. * except if they are shared between several contexts
  64. */
  65. void _starpu_node_destroy_rec(struct _starpu_sched_node * node, unsigned sched_ctx_id);
  66. int _starpu_tree_push_task(struct starpu_task * task);
  67. struct starpu_task * _starpu_tree_pop_task(unsigned sched_ctx_id);
  68. //this function must be called after all modification of tree
  69. void _starpu_tree_update_after_modification(struct _starpu_sched_tree * tree);
  70. ;
  71. //extern struct starpu_sched_policy _starpu_sched_tree_eager_policy;
  72. //extern struct starpu_sched_policy _starpu_sched_tree_random_policy;
  73. #endif