starpu_scheduler.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2011 Télécom-SudParis
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __STARPU_SCHEDULER_H__
  18. #define __STARPU_SCHEDULER_H__
  19. #include <starpu.h>
  20. #if ! defined(_MSC_VER)
  21. # include <pthread.h>
  22. #endif
  23. #ifdef STARPU_HAVE_HWLOC
  24. #include <hwloc.h>
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. struct starpu_task;
  31. struct starpu_machine_topology
  32. {
  33. unsigned nworkers;
  34. unsigned ncombinedworkers;
  35. unsigned nsched_ctxs;
  36. #ifdef STARPU_HAVE_HWLOC
  37. hwloc_topology_t hwtopology;
  38. #else
  39. /* We maintain ABI compatibility with and without hwloc */
  40. void *dummy;
  41. #endif
  42. unsigned nhwcpus;
  43. unsigned nhwcudagpus;
  44. unsigned nhwopenclgpus;
  45. unsigned ncpus;
  46. unsigned ncudagpus;
  47. unsigned nopenclgpus;
  48. /* Where to bind workers ? */
  49. unsigned workers_bindid[STARPU_NMAXWORKERS];
  50. /* Which GPU(s) do we use for CUDA ? */
  51. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  52. /* Which GPU(s) do we use for OpenCL ? */
  53. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  54. };
  55. /* This structure contains all the methods that implement a scheduling policy.
  56. * An application may specify which scheduling strategy in the "sched_policy"
  57. * field of the starpu_conf structure passed to the starpu_init function. */
  58. struct starpu_sched_policy
  59. {
  60. /* Initialize the scheduling policy. */
  61. void (*init_sched)(unsigned sched_ctx_id);
  62. /* Cleanup the scheduling policy. */
  63. void (*deinit_sched)(unsigned sched_ctx_id);
  64. /* Insert a task into the scheduler. */
  65. int (*push_task)(struct starpu_task *);
  66. /* Notify the scheduler that a task was directly pushed to the worker
  67. * without going through the scheduler. This method is called when a
  68. * task is explicitely assigned to a worker. This method therefore
  69. * permits to keep the timing state of the scheduler coherent even
  70. * when StarPU bypasses the scheduling strategy. */
  71. void (*push_task_notify)(struct starpu_task *, int workerid, unsigned sched_ctx_id);
  72. /* Get a task from the scheduler. The mutex associated to the worker is
  73. * already taken when this method is called. */
  74. struct starpu_task *(*pop_task)(unsigned sched_ctx_id);
  75. /* Remove all available tasks from the scheduler (tasks are chained by
  76. * the means of the prev and next fields of the starpu_task
  77. * structure). The mutex associated to the worker is already taken
  78. * when this method is called. */
  79. struct starpu_task *(*pop_every_task)(unsigned sched_ctx_id);
  80. /* This method is called every time a task is starting. (optional) */
  81. void (*pre_exec_hook)(struct starpu_task *);
  82. /* This method is called every time a task has been executed. (optional) */
  83. void (*post_exec_hook)(struct starpu_task *);
  84. /* Initialize scheduling structures corresponding to each worker. */
  85. void (*add_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  86. /* Deinitialize scheduling structures corresponding to each worker. */
  87. void (*remove_workers)(unsigned sched_ctx_id, int *workerids, unsigned nworkers);
  88. /* Name of the policy (optionnal) */
  89. const char *policy_name;
  90. /* Description of the policy (optionnal) */
  91. const char *policy_description;
  92. };
  93. struct starpu_sched_policy **starpu_sched_get_predefined_policies();
  94. /* When there is no available task for a worker, StarPU blocks this worker on a
  95. condition variable. This function specifies which condition variable (and the
  96. associated mutex) should be used to block (and to wake up) a worker. Note that
  97. multiple workers may use the same condition variable. For instance, in the case
  98. of a scheduling strategy with a single task queue, the same condition variable
  99. would be used to block and wake up all workers. */
  100. #if !defined(_MSC_VER) && !defined(STARPU_SIMGRID)
  101. void starpu_worker_get_sched_condition(int workerid, pthread_mutex_t **sched_mutex, pthread_cond_t **sched_cond);
  102. #endif
  103. /* Check if the worker specified by workerid can execute the codelet. */
  104. int starpu_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  105. /* The scheduling policy may put tasks directly into a worker's local queue so
  106. * that it is not always necessary to create its own queue when the local queue
  107. * is sufficient. If "back" not null, the task is put at the back of the queue
  108. * where the worker will pop tasks first. Setting "back" to 0 therefore ensures
  109. * a FIFO ordering. */
  110. int starpu_push_local_task(int workerid, struct starpu_task *task, int back);
  111. /*
  112. * Priorities
  113. */
  114. /* Provided for legacy reasons */
  115. #define STARPU_MIN_PRIO (starpu_sched_get_min_priority())
  116. #define STARPU_MAX_PRIO (starpu_sched_get_max_priority())
  117. /* By convention, the default priority level should be 0 so that we can
  118. * statically allocate tasks with a default priority. */
  119. #define STARPU_DEFAULT_PRIO 0
  120. int starpu_sched_get_min_priority(void);
  121. int starpu_sched_get_max_priority(void);
  122. void starpu_sched_set_min_priority(int min_prio);
  123. void starpu_sched_set_max_priority(int max_prio);
  124. /*
  125. * Parallel tasks
  126. */
  127. /* Register a new combined worker and get its identifier */
  128. int starpu_combined_worker_assign_workerid(int nworkers, int workerid_array[]);
  129. /* Get the description of a combined worker */
  130. int starpu_combined_worker_get_description(int workerid, int *worker_size, int **combined_workerid);
  131. /* Variant of starpu_worker_can_execute_task compatible with combined workers */
  132. int starpu_combined_worker_can_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  133. /*
  134. * Data prefetching
  135. */
  136. /* Whether STARPU_PREFETCH was set */
  137. int starpu_get_prefetch_flag(void);
  138. /* Prefetch data for a given task on a given node */
  139. int starpu_prefetch_task_input_on_node(struct starpu_task *task, unsigned node);
  140. /*
  141. * Performance predictions
  142. */
  143. /* Return the current date in us */
  144. double starpu_timing_now(void);
  145. /* Returns expected task duration in us */
  146. double starpu_task_expected_length(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  147. /* Returns an estimated speedup factor relative to CPU speed */
  148. double starpu_worker_get_relative_speedup(enum starpu_perf_archtype perf_archtype);
  149. /* Returns expected data transfer time in us */
  150. double starpu_task_expected_data_transfer_time(unsigned memory_node, struct starpu_task *task);
  151. /* Predict the transfer time (in us) to move a handle to a memory node */
  152. double starpu_data_expected_transfer_time(starpu_data_handle_t handle, unsigned memory_node, enum starpu_access_mode mode);
  153. /* Returns expected power consumption in J */
  154. double starpu_task_expected_power(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  155. /* Returns expected conversion time in ms (multiformat interface only) */
  156. double starpu_task_expected_conversion_time(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  157. /* Return the expected duration of the entire task bundle in us. */
  158. double starpu_task_bundle_expected_length(starpu_task_bundle_t bundle, enum starpu_perf_archtype arch, unsigned nimpl);
  159. /* Return the time (in us) expected to transfer all data used within the bundle */
  160. double starpu_task_bundle_expected_data_transfer_time(starpu_task_bundle_t bundle, unsigned memory_node);
  161. /* Return the expected power consumption of the entire task bundle in J. */
  162. double starpu_task_bundle_expected_power(starpu_task_bundle_t bundle, enum starpu_perf_archtype arch, unsigned nimpl);
  163. #ifdef __cplusplus
  164. }
  165. #endif
  166. #endif /* __STARPU_SCHEDULER_H__ */