starpu_scheduler.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  4. * Copyright (C) 2011 Télécom-SudParis
  5. * Copyright (C) 2011 INRIA
  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_SCHEDULER_H__
  19. #define __STARPU_SCHEDULER_H__
  20. #include <starpu.h>
  21. #include <starpu_config.h>
  22. #if ! defined(_MSC_VER)
  23. # include <pthread.h>
  24. #endif
  25. #ifdef STARPU_HAVE_HWLOC
  26. #include <hwloc.h>
  27. #endif
  28. struct starpu_task;
  29. struct starpu_machine_topology_s {
  30. unsigned nworkers;
  31. unsigned ncombinedworkers;
  32. unsigned nsched_ctxs;
  33. #ifdef STARPU_HAVE_HWLOC
  34. hwloc_topology_t hwtopology;
  35. #else
  36. /* We maintain ABI compatibility with and without hwloc */
  37. void *dummy;
  38. #endif
  39. unsigned nhwcpus;
  40. unsigned nhwcudagpus;
  41. unsigned nhwopenclgpus;
  42. unsigned ncpus;
  43. unsigned ncudagpus;
  44. unsigned nopenclgpus;
  45. unsigned ngordon_spus;
  46. /* Where to bind workers ? */
  47. unsigned workers_bindid[STARPU_NMAXWORKERS];
  48. /* Which GPU(s) do we use for CUDA ? */
  49. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  50. /* Which GPU(s) do we use for OpenCL ? */
  51. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  52. };
  53. /* This structure contains all the methods that implement a scheduling policy.
  54. * An application may specify which scheduling strategy in the "sched_policy"
  55. * field of the starpu_conf structure passed to the starpu_init function. */
  56. struct starpu_sched_policy_s {
  57. /* Initialize the scheduling policy. */
  58. void (*init_sched)(unsigned sched_ctx_id);
  59. /* Cleanup the scheduling policy. */
  60. void (*deinit_sched)(unsigned sched_ctx_id);
  61. /* Insert a task into the scheduler. */
  62. int (*push_task)(struct starpu_task *);
  63. /* Notify the scheduler that a task was directly pushed to the worker
  64. * without going through the scheduler. This method is called when a
  65. * task is explicitely assigned to a worker. This method therefore
  66. * permits to keep the timing state of the scheduler coherent even
  67. * when StarPU bypasses the scheduling strategy. */
  68. void (*push_task_notify)(struct starpu_task *, int workerid);
  69. /* Get a task from the scheduler. The mutex associated to the worker is
  70. * already taken when this method is called. */
  71. struct starpu_task *(*pop_task)();
  72. /* Remove all available tasks from the scheduler (tasks are chained by
  73. * the means of the prev and next fields of the starpu_task
  74. * structure). The mutex associated to the worker is already taken
  75. * when this method is called. */
  76. struct starpu_task *(*pop_every_task)();
  77. /* This method is called every time a task has been executed. (optionnal) */
  78. void (*post_exec_hook)(struct starpu_task *);
  79. /* Initialize the scheduling policy for added workers. */
  80. void (*add_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  81. /* Deinitialize the scheduling policy for removed workers. */
  82. void (*remove_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  83. /* Name of the policy (optionnal) */
  84. const char *policy_name;
  85. /* Description of the policy (optionnal) */
  86. const char *policy_description;
  87. };
  88. struct worker_collection {
  89. void *workerids;
  90. unsigned nworkers;
  91. pthread_key_t cursor_key;
  92. int type;
  93. unsigned (*has_next)(struct worker_collection *workers);
  94. int (*get_next)(struct worker_collection *workers);
  95. int (*add)(struct worker_collection *workers, int worker);
  96. int (*remove)(struct worker_collection *workers, int worker);
  97. void* (*init)(struct worker_collection *workers);
  98. void (*deinit)(struct worker_collection *workers);
  99. void (*init_cursor)(struct worker_collection *workers);
  100. void (*deinit_cursor)(struct worker_collection *workers);
  101. };
  102. #define WORKER_LIST 0
  103. struct starpu_sched_ctx_hypervisor_criteria {
  104. void (*idle_time_cb)(unsigned sched_ctx, int worker, double idle_time);
  105. void (*reset_idle_time_cb)(unsigned sched_ctx, int worker);
  106. void (*working_time_cb)(unsigned sched_ctx, double working_time);
  107. void (*pushed_task_cb)(unsigned sched_ctx, int worker);
  108. void (*poped_task_cb)(unsigned sched_ctx, int worker, double flops);
  109. void (*post_exec_hook_cb)(unsigned sched_ctx, int taskid);
  110. };
  111. #ifdef STARPU_BUILD_SCHED_CTX_HYPERVISOR
  112. unsigned starpu_create_sched_ctx_with_criteria(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_name, struct starpu_sched_ctx_hypervisor_criteria **criteria);
  113. void starpu_call_poped_task_cb(int workerid, unsigned sched_ctx_id, double flops);
  114. void starpu_call_pushed_task_cb(int workerid, unsigned sched_ctx_id);
  115. #endif //STARPU_BUILD_SCHED_CTX_HYPERVISOR
  116. unsigned starpu_create_sched_ctx(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_name);
  117. void starpu_delete_sched_ctx(unsigned sched_ctx_id, unsigned inheritor_sched_ctx_id);
  118. void starpu_add_workers_to_sched_ctx(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx);
  119. void starpu_remove_workers_from_sched_ctx(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx);
  120. void starpu_set_sched_ctx_policy_data(unsigned sched_ctx, void* policy_data);
  121. void* starpu_get_sched_ctx_policy_data(unsigned sched_ctx);
  122. void starpu_worker_set_sched_condition(unsigned sched_ctx, int workerid, pthread_mutex_t *sched_mutex, pthread_cond_t *sched_cond);
  123. void starpu_worker_get_sched_condition(unsigned sched_ctx, int workerid, pthread_mutex_t **sched_mutex, pthread_cond_t **sched_cond);
  124. void starpu_worker_init_sched_condition(unsigned sched_ctx, int workerid);
  125. void starpu_worker_deinit_sched_condition(unsigned sched_ctx, int workerid);
  126. void starpu_create_worker_collection_for_sched_ctx(unsigned sched_ctx_id, int type);
  127. struct worker_collection* starpu_get_worker_collection_of_sched_ctx(unsigned sched_ctx_id);
  128. pthread_mutex_t* starpu_get_changing_ctx_mutex(unsigned sched_ctx_id);
  129. void starpu_set_sched_ctx(unsigned *sched_ctx);
  130. unsigned starpu_get_sched_ctx();
  131. unsigned starpu_get_nworkers_of_sched_ctx(unsigned sched_ctx);
  132. /* Check if the worker specified by workerid can execute the codelet. */
  133. int starpu_worker_may_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  134. /* The scheduling policy may put tasks directly into a worker's local queue so
  135. * that it is not always necessary to create its own queue when the local queue
  136. * is sufficient. If "back" not null, the task is put at the back of the queue
  137. * where the worker will pop tasks first. Setting "back" to 0 therefore ensures
  138. * a FIFO ordering. */
  139. int starpu_push_local_task(int workerid, struct starpu_task *task, int back);
  140. /*
  141. * Priorities
  142. */
  143. /* Provided for legacy reasons */
  144. #define STARPU_MIN_PRIO (starpu_sched_get_min_priority())
  145. #define STARPU_MAX_PRIO (starpu_sched_get_max_priority())
  146. /* By convention, the default priority level should be 0 so that we can
  147. * statically allocate tasks with a default priority. */
  148. #define STARPU_DEFAULT_PRIO 0
  149. int starpu_sched_get_min_priority(void);
  150. int starpu_sched_get_max_priority(void);
  151. void starpu_sched_set_min_priority(int min_prio);
  152. void starpu_sched_set_max_priority(int max_prio);
  153. /*
  154. * Parallel tasks
  155. */
  156. /* Register a new combined worker and get its identifier */
  157. int starpu_combined_worker_assign_workerid(int nworkers, int workerid_array[]);
  158. /* Initialize combined workers */
  159. void _starpu_sched_find_worker_combinations(struct starpu_machine_topology_s *topology);
  160. /* Get the description of a combined worker */
  161. int starpu_combined_worker_get_description(int workerid, int *worker_size, int **combined_workerid);
  162. /* Variant of starpu_worker_may_execute_task compatible with combined workers */
  163. int starpu_combined_worker_may_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  164. /*
  165. * Data prefetching
  166. */
  167. /* Whether STARPU_PREFETCH was set */
  168. int starpu_get_prefetch_flag(void);
  169. /* Prefetch data for a given task on a given node */
  170. int starpu_prefetch_task_input_on_node(struct starpu_task *task, uint32_t node);
  171. /*
  172. * Performance predictions
  173. */
  174. /* Return the current date */
  175. double starpu_timing_now(void);
  176. /* Returns expected task duration in µs */
  177. double starpu_task_expected_length(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  178. /* Returns an estimated speedup factor relative to CPU speed */
  179. double starpu_worker_get_relative_speedup(enum starpu_perf_archtype perf_archtype);
  180. /* Returns expected data transfer time in µs */
  181. double starpu_task_expected_data_transfer_time(uint32_t memory_node, struct starpu_task *task);
  182. /* Predict the transfer time (in µs) to move a handle to a memory node */
  183. double starpu_data_expected_transfer_time(starpu_data_handle handle, unsigned memory_node, starpu_access_mode mode);
  184. /* Returns expected power consumption in J */
  185. double starpu_task_expected_power(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  186. /* Waits until all the tasks of a worker, already submitted, have been executed */
  187. int starpu_wait_for_all_tasks_of_worker(int workerid);
  188. /* Waits until all the tasks of a bunch of workers have been executed */
  189. int starpu_wait_for_all_tasks_of_workers(int *workerids_ctx, int nworkers_ctx);
  190. #endif /* __STARPU_SCHEDULER_H__ */