starpu_sched_ctx.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 - 2012 INRIA
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __STARPU_SCHED_CTX_H__
  17. #define __STARPU_SCHED_CTX_H__
  18. #include <starpu.h>
  19. #ifdef __cplusplus
  20. extern "C"
  21. {
  22. #endif
  23. unsigned starpu_sched_ctx_create(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_ctx_name);
  24. /* create a context indicating an approximate interval of resources */
  25. unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_name,
  26. int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus,
  27. unsigned allow_overlap);
  28. void starpu_sched_ctx_add_workers(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx_id);
  29. void starpu_sched_ctx_remove_workers(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx_id);
  30. void starpu_sched_ctx_delete(unsigned sched_ctx_id);
  31. /* indicate which context whill inherit the resources of this context when he will be deleted */
  32. void starpu_sched_ctx_set_inheritor(unsigned sched_ctx_id, unsigned inheritor);
  33. /* indicate that the current thread is submitting only to the current context */
  34. void starpu_sched_ctx_set_context(unsigned *sched_ctx_id);
  35. /* find out to which context is submitting the current thread */
  36. unsigned starpu_sched_ctx_get_context(void);
  37. /* stop submitting tasks from the empty context list until the next time the context has
  38. time to check the empty context list*/
  39. void starpu_sched_ctx_stop_task_submission(void);
  40. /* indicate starpu that hte application finished submitting to this context in order to
  41. move the workers to the inheritor as soon as possible */
  42. void starpu_sched_ctx_finished_submit(unsigned sched_ctx_id);
  43. /*
  44. * CONNECTION WITH THE HYPERVISOR
  45. */
  46. /* performance counters used by the starpu to indicate the hypervisor
  47. how the application and the resources are executing */
  48. struct starpu_sched_ctx_performance_counters
  49. {
  50. /* tell the hypervisor for how long a worker was idle in a certain context */
  51. void (*notify_idle_cycle)(unsigned sched_ctx_id, int worker, double idle_time);
  52. /* tell the hypervisor when a worker stoped being idle in a certain context */
  53. void (*notify_idle_end)(unsigned sched_ctx_id, int worker);
  54. /* tell the hypervisor when a task was pushed on a worker in a certain context */
  55. void (*notify_pushed_task)(unsigned sched_ctx_id, int worker);
  56. /* tell the hypervisor when a task was poped from a worker in a certain context */
  57. void (*notify_poped_task)(unsigned sched_ctx_id, int worker, struct starpu_task *task, size_t data_size, uint32_t footprint);
  58. /* tell the hypervisor when a task finished executing in a certain context */
  59. void (*notify_post_exec_hook)(unsigned sched_ctx_id, int taskid);
  60. /* tell the hypervisor when a task was submitted to a certain context */
  61. void (*notify_submitted_job)(struct starpu_task *task, uint32_t footprint);
  62. /* tell the hypervisor when a context was deleted */
  63. void (*notify_delete_context)(unsigned sched_ctx);
  64. };
  65. #ifdef STARPU_USE_SC_HYPERVISOR
  66. /* indicates to starpu the pointer to the performance counte */
  67. void starpu_sched_ctx_set_perf_counters(unsigned sched_ctx_id, struct starpu_sched_ctx_performance_counters *perf_counters);
  68. /* callback that lets the scheduling policy tell the hypervisor that a task was pushed on a worker */
  69. void starpu_sched_ctx_call_pushed_task_cb(int workerid, unsigned sched_ctx_id);
  70. #endif //STARPU_USE_SC_HYPERVISOR
  71. /* allow the hypervisor to let starpu know he's initialised */
  72. void starpu_sched_ctx_notify_hypervisor_exists(void);
  73. /* ask starpu if he is informed if the hypervisor is initialised */
  74. unsigned starpu_sched_ctx_check_if_hypervisor_exists(void);
  75. /*
  76. * POLICY DATA
  77. */
  78. /* allow the scheduling policy to have its own data in a context, like a private list of tasks, mutexes, conds, etc. */
  79. void starpu_sched_ctx_set_policy_data(unsigned sched_ctx_id, void *policy_data);
  80. /* return the scheduling policy private data */
  81. void* starpu_sched_ctx_get_policy_data(unsigned sched_ctx_id);
  82. /*
  83. * WORKERS IN CONTEXT
  84. */
  85. /* create a worker collection for a context, the type can be only STARPU_WORKER_LIST for now, which corresponds to a simple list */
  86. struct starpu_worker_collection* starpu_sched_ctx_create_worker_collection(unsigned sched_ctx_id, enum starpu_worker_collection_type type);
  87. /* free the worker collection when removing the context */
  88. void starpu_sched_ctx_delete_worker_collection(unsigned sched_ctx_id);
  89. /*return the worker collection */
  90. struct starpu_worker_collection* starpu_sched_ctx_get_worker_collection(unsigned sched_ctx_id);
  91. /* return the number of workers in the sched_ctx's collection */
  92. unsigned starpu_sched_ctx_get_nworkers(unsigned sched_ctx_id);
  93. /* return the number of shared workers in the sched_ctx's collection */
  94. unsigned starpu_sched_ctx_get_nshared_workers(unsigned sched_ctx_id, unsigned sched_ctx_id2);
  95. /* return 1 if the worker belongs to the context and 0 otherwise */
  96. unsigned starpu_sched_ctx_contains_worker(int workerid, unsigned sched_ctx_id);
  97. /* check if a worker is shared between several contexts */
  98. unsigned starpu_sched_ctx_overlapping_ctxs_on_worker(int workerid);
  99. /* manage sharing of resources between contexts: checkOB which ctx has its turn to pop */
  100. unsigned starpu_sched_ctx_is_ctxs_turn(int workerid, unsigned sched_ctx_id);
  101. /* manage sharing of resources between contexts: by default a round_robin strategy
  102. is executed but the user can interfere to tell which ctx has its turn to pop */
  103. void starpu_sched_ctx_set_turn_to_other_ctx(int workerid, unsigned sched_ctx_id);
  104. /* time sharing a resources, indicate how long a worker has been active in
  105. the current sched_ctx */
  106. double starpu_sched_ctx_get_max_time_worker_on_ctx(void);
  107. /*
  108. * Priorities
  109. */
  110. /* get min priority for the scheduler of the global context */
  111. int starpu_sched_get_min_priority(void);
  112. /* get max priority for the scheduler of the global context */
  113. int starpu_sched_get_max_priority(void);
  114. /* set min priority for the scheduler of the global context */
  115. int starpu_sched_set_min_priority(int min_prio);
  116. /* set max priority for the scheduler of the global context */
  117. int starpu_sched_set_max_priority(int max_prio);
  118. /* get min priority for the scheduler of the scheduling context indicated */
  119. int starpu_sched_ctx_get_min_priority(unsigned sched_ctx_id);
  120. /* get max priority for the scheduler of the scheduling context indicated */
  121. int starpu_sched_ctx_get_max_priority(unsigned sched_ctx_id);
  122. /* set min priority for the scheduler of the scheduling context indicated */
  123. int starpu_sched_ctx_set_min_priority(unsigned sched_ctx_id, int min_prio);
  124. /* set max priority for the scheduler of the scheduling context indicated */
  125. int starpu_sched_ctx_set_max_priority(unsigned sched_ctx_id, int max_prio);
  126. /* Provided for legacy reasons */
  127. #define STARPU_MIN_PRIO (starpu_sched_get_min_priority())
  128. #define STARPU_MAX_PRIO (starpu_sched_get_max_priority())
  129. /* By convention, the default priority level should be 0 so that we can
  130. * statically allocate tasks with a default priority. */
  131. #define STARPU_DEFAULT_PRIO 0
  132. /* execute any parallel code on the workers of the sched_ctx (workers are blocked) */
  133. void* starpu_sched_ctx_exec_parallel_code(void* (*func)(void*), void* param, unsigned sched_ctx_id);
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif /* __STARPU_SCHED_CTX_H__ */