starpu_scheduler.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 ctx_id);
  59. /* Initialize the scheduling policy only for certain workers. */
  60. void (*init_sched_for_workers)(unsigned ctx_id, unsigned n_added_workers);
  61. /* Cleanup the scheduling policy. */
  62. void (*deinit_sched)(unsigned ctx_id);
  63. /* Insert a task into the scheduler. */
  64. int (*push_task)(struct starpu_task *, unsigned ctx_id);
  65. /* Notify the scheduler that a task was directly pushed to the worker
  66. * without going through the scheduler. This method is called when a
  67. * task is explicitely assigned to a worker. This method therefore
  68. * permits to keep the timing state of the scheduler coherent even
  69. * when StarPU bypasses the scheduling strategy. */
  70. void (*push_task_notify)(struct starpu_task *, int workerid, unsigned ctx_id);
  71. /* Get a task from the scheduler. The mutex associated to the worker is
  72. * already taken when this method is called. */
  73. struct starpu_task *(*pop_task)(unsigned ctx_id);
  74. /* Remove all available tasks from the scheduler (tasks are chained by
  75. * the means of the prev and next fields of the starpu_task
  76. * structure). The mutex associated to the worker is already taken
  77. * when this method is called. */
  78. struct starpu_task *(*pop_every_task)(unsigned ctx_id);
  79. /* This method is called every time a task has been executed. (optionnal) */
  80. void (*post_exec_hook)(struct starpu_task *, unsigned ctx_id);
  81. /* Name of the policy (optionnal) */
  82. const char *policy_name;
  83. /* Description of the policy (optionnal) */
  84. const char *policy_description;
  85. };
  86. unsigned starpu_create_sched_ctx(const char *policy_name, int *workerids_in_ctx, int nworkerids_in_ctx, const char *sched_name);
  87. void starpu_delete_sched_ctx(unsigned sched_ctx_id, unsigned inheritor_sched_ctx_id);
  88. void starpu_add_workers_to_sched_ctx(int *workerids_in_ctx, int nworkerids_in_ctx, unsigned sched_ctx);
  89. void starpu_remove_workers_from_sched_ctx(int *workerids_in_ctx, int nworkerids_in_ctx, unsigned sched_ctx);
  90. /* When there is no available task for a worker, StarPU blocks this worker on a
  91. condition variable. This function specifies which condition variable (and the
  92. associated mutex) should be used to block (and to wake up) a worker. Note that
  93. multiple workers may use the same condition variable. For instance, in the case
  94. of a scheduling strategy with a single task queue, the same condition variable
  95. would be used to block and wake up all workers. The initialization method of a
  96. scheduling strategy (init_sched) must call this function once per worker. */
  97. #if !defined(_MSC_VER)
  98. void starpu_worker_set_sched_condition(int workerid, pthread_cond_t *sched_cond, pthread_mutex_t *sched_mutex);
  99. #endif
  100. /* Check if the worker specified by workerid can execute the codelet. */
  101. int starpu_worker_may_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  102. /* The scheduling policy may put tasks directly into a worker's local queue so
  103. * that it is not always necessary to create its own queue when the local queue
  104. * is sufficient. If "back" not null, the task is put at the back of the queue
  105. * where the worker will pop tasks first. Setting "back" to 0 therefore ensures
  106. * a FIFO ordering. */
  107. int starpu_push_local_task(int workerid, struct starpu_task *task, int back);
  108. /*
  109. * Priorities
  110. */
  111. /* Provided for legacy reasons */
  112. #define STARPU_MIN_PRIO (starpu_sched_get_min_priority())
  113. #define STARPU_MAX_PRIO (starpu_sched_get_max_priority())
  114. /* By convention, the default priority level should be 0 so that we can
  115. * statically allocate tasks with a default priority. */
  116. #define STARPU_DEFAULT_PRIO 0
  117. int starpu_sched_get_min_priority(void);
  118. int starpu_sched_get_max_priority(void);
  119. void starpu_sched_set_min_priority(int min_prio);
  120. void starpu_sched_set_max_priority(int max_prio);
  121. /*
  122. * Parallel tasks
  123. */
  124. /* Register a new combined worker and get its identifier */
  125. int starpu_combined_worker_assign_workerid(int nworkers, int workerid_array[]);
  126. /* Initialize combined workers */
  127. void _starpu_sched_find_worker_combinations(struct starpu_machine_topology_s *topology);
  128. /* Get the description of a combined worker */
  129. int starpu_combined_worker_get_description(int workerid, int *worker_size, int **combined_workerid);
  130. /* Variant of starpu_worker_may_execute_task compatible with combined workers */
  131. int starpu_combined_worker_may_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  132. /*
  133. * Data prefetching
  134. */
  135. /* Whether STARPU_PREFETCH was set */
  136. int starpu_get_prefetch_flag(void);
  137. /* Prefetch data for a given task on a given node */
  138. int starpu_prefetch_task_input_on_node(struct starpu_task *task, uint32_t node);
  139. /*
  140. * Performance predictions
  141. */
  142. /* Return the current date */
  143. double starpu_timing_now(void);
  144. /* Returns expected task duration in µs */
  145. double starpu_task_expected_length(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  146. /* Returns an estimated speedup factor relative to CPU speed */
  147. double starpu_worker_get_relative_speedup(enum starpu_perf_archtype perf_archtype);
  148. /* Returns expected data transfer time in µs */
  149. double starpu_task_expected_data_transfer_time(uint32_t memory_node, struct starpu_task *task);
  150. /* Predict the transfer time (in µs) to move a handle to a memory node */
  151. double starpu_data_expected_transfer_time(starpu_data_handle handle, unsigned memory_node, starpu_access_mode mode);
  152. /* Returns expected power consumption in J */
  153. double starpu_task_expected_power(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  154. /* Waits until all the tasks of a worker, already submitted, have been executed */
  155. int starpu_wait_for_all_tasks_of_worker(int workerid);
  156. /* Waits until all the tasks of a bunch of workers have been executed */
  157. int starpu_wait_for_all_tasks_of_workers(int *workerids_in_ctx, int nworkerids_in_ctx);
  158. #endif /* __STARPU_SCHEDULER_H__ */