workers.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  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 __WORKERS_H__
  18. #define __WORKERS_H__
  19. #include <starpu.h>
  20. #include <starpu_scheduler.h>
  21. #include <common/config.h>
  22. #include <pthread.h>
  23. #include <common/timing.h>
  24. #include <common/fxt.h>
  25. #include <core/jobs.h>
  26. #include <core/perfmodel/perfmodel.h>
  27. #include <core/sched_policy.h>
  28. #include <core/topology.h>
  29. #include <core/errorcheck.h>
  30. #ifdef STARPU_HAVE_HWLOC
  31. #include <hwloc.h>
  32. #endif
  33. #ifdef STARPU_USE_CUDA
  34. #include <drivers/cuda/driver_cuda.h>
  35. #endif
  36. #ifdef STARPU_USE_OPENCL
  37. #include <drivers/opencl/driver_opencl.h>
  38. #endif
  39. #ifdef STARPU_USE_GORDON
  40. #include <drivers/gordon/driver_gordon.h>
  41. #endif
  42. #include <drivers/cpu/driver_cpu.h>
  43. #include <datawizard/datawizard.h>
  44. #include <starpu_parameters.h>
  45. struct _starpu_worker
  46. {
  47. struct _starpu_machine_config *config;
  48. pthread_mutex_t mutex;
  49. enum starpu_archtype arch; /* what is the type of worker ? */
  50. uint32_t worker_mask; /* what is the type of worker ? */
  51. enum starpu_perf_archtype perf_arch; /* in case there are different models of the same arch */
  52. pthread_t worker_thread; /* the thread which runs the worker */
  53. int devid; /* which cpu/gpu/etc is controlled by the workker ? */
  54. int bindid; /* which cpu is the driver bound to ? (logical index) */
  55. int workerid; /* uniquely identify the worker among all processing units types */
  56. int combined_workerid; /* combined worker currently using this worker */
  57. int current_rank; /* current rank in case the worker is used in a parallel fashion */
  58. int worker_size; /* size of the worker in case we use a combined worker */
  59. pthread_cond_t ready_cond; /* indicate when the worker is ready */
  60. unsigned memory_node; /* which memory node is the worker associated with ? */
  61. pthread_cond_t *sched_cond; /* condition variable used when the worker waits for tasks. */
  62. pthread_mutex_t *sched_mutex; /* mutex protecting sched_cond */
  63. struct starpu_task_list local_tasks; /* this queue contains tasks that have been explicitely submitted to that queue */
  64. struct starpu_task *current_task; /* task currently executed by this worker */
  65. struct _starpu_worker_set *set; /* in case this worker belongs to a set */
  66. struct _starpu_job_list *terminated_jobs; /* list of pending jobs which were executed */
  67. unsigned worker_is_running;
  68. unsigned worker_is_initialized;
  69. enum _starpu_worker_status status; /* what is the worker doing now ? (eg. CALLBACK) */
  70. char name[48];
  71. char short_name[10];
  72. unsigned run_by_starpu; /* Is this run by StarPU or directly by the application ? */
  73. #ifdef __GLIBC__
  74. cpu_set_t initial_cpu_set;
  75. cpu_set_t current_cpu_set;
  76. #endif /* __GLIBC__ */
  77. #ifdef STARPU_HAVE_HWLOC
  78. hwloc_cpuset_t initial_hwloc_cpu_set;
  79. hwloc_cpuset_t current_hwloc_cpu_set;
  80. #endif
  81. };
  82. struct _starpu_combined_worker
  83. {
  84. enum starpu_perf_archtype perf_arch; /* in case there are different models of the same arch */
  85. uint32_t worker_mask; /* what is the type of workers ? */
  86. int worker_size;
  87. unsigned memory_node; /* which memory node is associated that worker to ? */
  88. int combined_workerid[STARPU_NMAXWORKERS];
  89. #ifdef __GLIBC__
  90. cpu_set_t cpu_set;
  91. #endif /* __GLIBC__ */
  92. #ifdef STARPU_HAVE_HWLOC
  93. hwloc_cpuset_t hwloc_cpu_set;
  94. #endif
  95. };
  96. /* in case a single CPU worker may control multiple
  97. * accelerators (eg. Gordon for n SPUs) */
  98. struct _starpu_worker_set
  99. {
  100. pthread_mutex_t mutex;
  101. pthread_t worker_thread; /* the thread which runs the worker */
  102. unsigned nworkers;
  103. unsigned joined; /* only one thread may call pthread_join*/
  104. void *retval;
  105. struct _starpu_worker *workers;
  106. pthread_cond_t ready_cond; /* indicate when the set is ready */
  107. unsigned set_is_initialized;
  108. };
  109. struct _starpu_machine_config
  110. {
  111. struct starpu_machine_topology topology;
  112. #ifdef STARPU_HAVE_HWLOC
  113. int cpu_depth;
  114. #endif
  115. /* Where to bind workers ? */
  116. int current_bindid;
  117. /* Which GPU(s) do we use for CUDA ? */
  118. int current_cuda_gpuid;
  119. /* Which GPU(s) do we use for OpenCL ? */
  120. int current_opencl_gpuid;
  121. /* Basic workers : each of this worker is running its own driver and
  122. * can be combined with other basic workers. */
  123. struct _starpu_worker workers[STARPU_NMAXWORKERS];
  124. /* Combined workers: these worker are a combination of basic workers
  125. * that can run parallel tasks together. */
  126. struct _starpu_combined_worker combined_workers[STARPU_NMAX_COMBINEDWORKERS];
  127. /* This bitmask indicates which kinds of worker are available. For
  128. * instance it is possible to test if there is a CUDA worker with
  129. * the result of (worker_mask & STARPU_CUDA). */
  130. uint32_t worker_mask;
  131. /* either the user given configuration passed to starpu_init or a default configuration */
  132. struct starpu_conf *conf;
  133. /* set to 1 if no conf has been given by the user, it
  134. * indicates the memory allocated for the default
  135. * configuration should be freed on shutdown */
  136. int default_conf;
  137. /* this flag is set until the runtime is stopped */
  138. unsigned running;
  139. /* this flag is set until the application is finished submitting tasks */
  140. unsigned submitting;
  141. };
  142. /* Has starpu_shutdown already been called ? */
  143. unsigned _starpu_machine_is_running(void);
  144. /* Check if there is a worker that may execute the task. */
  145. uint32_t _starpu_worker_exists(struct starpu_task *);
  146. /* Is there a worker that can execute CUDA code ? */
  147. uint32_t _starpu_can_submit_cuda_task(void);
  148. /* Is there a worker that can execute CPU code ? */
  149. uint32_t _starpu_can_submit_cpu_task(void);
  150. /* Is there a worker that can execute OpenCL code ? */
  151. uint32_t _starpu_can_submit_opencl_task(void);
  152. /* Check whether there is anything that the worker should do instead of
  153. * sleeping (waiting on something to happen). */
  154. unsigned _starpu_worker_can_block(unsigned memnode);
  155. /* This function must be called to block a worker. It puts the worker in a
  156. * sleeping state until there is some event that forces the worker to wake up.
  157. * */
  158. void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *mutex);
  159. /* The _starpu_worker structure describes all the state of a StarPU worker.
  160. * This function sets the pthread key which stores a pointer to this structure.
  161. * */
  162. void _starpu_set_local_worker_key(struct _starpu_worker *worker);
  163. /* Returns the _starpu_worker structure that describes the state of the
  164. * current worker. */
  165. struct _starpu_worker *_starpu_get_local_worker_key(void);
  166. /* Returns the _starpu_worker structure that describes the state of the
  167. * specified worker. */
  168. struct _starpu_worker *_starpu_get_worker_struct(unsigned id);
  169. struct _starpu_combined_worker *_starpu_get_combined_worker_struct(unsigned id);
  170. int _starpu_is_initialized(void);
  171. /* Returns the structure that describes the overall machine configuration (eg.
  172. * all workers and topology). */
  173. struct _starpu_machine_config *_starpu_get_machine_config(void);
  174. /* Retrieve the status which indicates what the worker is currently doing. */
  175. enum _starpu_worker_status _starpu_worker_get_status(int workerid);
  176. /* Change the status of the worker which indicates what the worker is currently
  177. * doing (eg. executing a callback). */
  178. void _starpu_worker_set_status(int workerid, enum _starpu_worker_status status);
  179. /* TODO move */
  180. unsigned _starpu_execute_registered_progression_hooks(void);
  181. #endif // __WORKERS_H__