starpu_scheduler.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. *
  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. #include <starpu_config.h>
  21. #if ! defined(_MSC_VER)
  22. # include <pthread.h>
  23. #endif
  24. #ifdef STARPU_HAVE_HWLOC
  25. #include <hwloc.h>
  26. #endif
  27. struct starpu_task;
  28. struct starpu_machine_topology_s {
  29. unsigned nworkers;
  30. unsigned ncombinedworkers;
  31. #ifdef STARPU_HAVE_HWLOC
  32. hwloc_topology_t hwtopology;
  33. #else
  34. /* We maintain ABI compatibility with and without hwloc */
  35. void *dummy;
  36. #endif
  37. unsigned nhwcpus;
  38. unsigned nhwcudagpus;
  39. unsigned nhwopenclgpus;
  40. unsigned ncpus;
  41. unsigned ncudagpus;
  42. unsigned nopenclgpus;
  43. unsigned ngordon_spus;
  44. /* Where to bind workers ? */
  45. unsigned workers_bindid[STARPU_NMAXWORKERS];
  46. /* Which GPU(s) do we use for CUDA ? */
  47. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  48. /* Which GPU(s) do we use for OpenCL ? */
  49. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  50. };
  51. /* This structure contains all the methods that implement a scheduling policy.
  52. * An application may specify which scheduling strategy in the "sched_policy"
  53. * field of the starpu_conf structure passed to the starpu_init function. */
  54. struct starpu_sched_policy_s {
  55. /* Initialize the scheduling policy. */
  56. void (*init_sched)(struct starpu_machine_topology_s *, struct starpu_sched_policy_s *);
  57. /* Cleanup the scheduling policy. */
  58. void (*deinit_sched)(struct starpu_machine_topology_s *, struct starpu_sched_policy_s *);
  59. /* Insert a task into the scheduler. */
  60. int (*push_task)(struct starpu_task *);
  61. /* Notify the scheduler that a task was directly pushed to the worker
  62. * without going through the scheduler. This method is called when a
  63. * task is explicitely assigned to a worker. This method therefore
  64. * permits to keep the timing state of the scheduler coherent even
  65. * when StarPU bypasses the scheduling strategy. */
  66. void (*push_task_notify)(struct starpu_task *, int workerid);
  67. /* Get a task from the scheduler. The mutex associated to the worker is
  68. * already taken when this method is called. */
  69. struct starpu_task *(*pop_task)(void);
  70. /* Remove all available tasks from the scheduler (tasks are chained by
  71. * the means of the prev and next fields of the starpu_task
  72. * structure). The mutex associated to the worker is already taken
  73. * when this method is called. */
  74. struct starpu_task *(*pop_every_task)(void);
  75. /* This method is called every time a task has been executed. (optionnal) */
  76. void (*post_exec_hook)(struct starpu_task *);
  77. /* Name of the policy (optionnal) */
  78. const char *policy_name;
  79. /* Description of the policy (optionnal) */
  80. const char *policy_description;
  81. };
  82. /* When there is no available task for a worker, StarPU blocks this worker on a
  83. condition variable. This function specifies which condition variable (and the
  84. associated mutex) should be used to block (and to wake up) a worker. Note that
  85. multiple workers may use the same condition variable. For instance, in the case
  86. of a scheduling strategy with a single task queue, the same condition variable
  87. would be used to block and wake up all workers. The initialization method of a
  88. scheduling strategy (init_sched) must call this function once per worker. */
  89. #if !defined(_MSC_VER)
  90. void starpu_worker_set_sched_condition(int workerid, pthread_cond_t *sched_cond, pthread_mutex_t *sched_mutex);
  91. #endif
  92. /* Check if the worker specified by workerid can execute the codelet. */
  93. int starpu_worker_may_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  94. /* The scheduling policy may put tasks directly into a worker's local queue so
  95. * that it is not always necessary to create its own queue when the local queue
  96. * is sufficient. If "back" not null, the task is put at the back of the queue
  97. * where the worker will pop tasks first. Setting "back" to 0 therefore ensures
  98. * a FIFO ordering. */
  99. int starpu_push_local_task(int workerid, struct starpu_task *task, int back);
  100. /*
  101. * Priorities
  102. */
  103. /* Provided for legacy reasons */
  104. #define STARPU_MIN_PRIO (starpu_sched_get_min_priority())
  105. #define STARPU_MAX_PRIO (starpu_sched_get_max_priority())
  106. /* By convention, the default priority level should be 0 so that we can
  107. * statically allocate tasks with a default priority. */
  108. #define STARPU_DEFAULT_PRIO 0
  109. int starpu_sched_get_min_priority(void);
  110. int starpu_sched_get_max_priority(void);
  111. void starpu_sched_set_min_priority(int min_prio);
  112. void starpu_sched_set_max_priority(int max_prio);
  113. /*
  114. * Parallel tasks
  115. */
  116. /* Register a new combined worker and get its identifier */
  117. int starpu_combined_worker_assign_workerid(int nworkers, int workerid_array[]);
  118. /* Initialize combined workers */
  119. void _starpu_sched_find_worker_combinations(struct starpu_machine_topology_s *topology);
  120. /* Get the description of a combined worker */
  121. int starpu_combined_worker_get_description(int workerid, int *worker_size, int **combined_workerid);
  122. /* Variant of starpu_worker_may_execute_task compatible with combined workers */
  123. int starpu_combined_worker_may_execute_task(unsigned workerid, struct starpu_task *task, unsigned nimpl);
  124. /*
  125. * Data prefetching
  126. */
  127. /* Whether STARPU_PREFETCH was set */
  128. int starpu_get_prefetch_flag(void);
  129. /* Prefetch data for a given task on a given node */
  130. int starpu_prefetch_task_input_on_node(struct starpu_task *task, uint32_t node);
  131. /*
  132. * Performance predictions
  133. */
  134. /* Return the current date */
  135. double starpu_timing_now(void);
  136. /* Returns expected task duration in µs */
  137. double starpu_task_expected_length(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  138. /* Returns an estimated speedup factor relative to CPU speed */
  139. double starpu_worker_get_relative_speedup(enum starpu_perf_archtype perf_archtype);
  140. /* Returns expected data transfer time in µs */
  141. double starpu_task_expected_data_transfer_time(uint32_t memory_node, struct starpu_task *task);
  142. /* Predict the transfer time (in µs) to move a handle to a memory node */
  143. double starpu_data_expected_transfer_time(starpu_data_handle handle, unsigned memory_node, starpu_access_mode mode);
  144. /* Returns expected power consumption in J */
  145. double starpu_task_expected_power(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl);
  146. #endif /* __STARPU_SCHEDULER_H__ */