workers.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010 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_s {
  46. struct starpu_machine_config_s *config;
  47. pthread_mutex_t mutex;
  48. enum starpu_archtype arch; /* what is the type of worker ? */
  49. uint32_t worker_mask; /* what is the type of worker ? */
  50. enum starpu_perf_archtype perf_arch; /* in case there are different models of the same arch */
  51. pthread_t worker_thread; /* the thread which runs the worker */
  52. int devid; /* which cpu/gpu/etc is controlled by the workker ? */
  53. int bindid; /* which cpu is the driver bound to ? */
  54. int workerid; /* uniquely identify the worker among all processing units types */
  55. int combined_workerid; /* combined worker currently using this worker */
  56. int current_rank; /* current rank in case the worker is used in a parallel fashion */
  57. int worker_size; /* size of the worker in case we use a combined worker */
  58. pthread_cond_t ready_cond; /* indicate when the worker is ready */
  59. unsigned memory_node; /* which memory node is associated that worker to ? */
  60. pthread_cond_t *sched_cond; /* condition variable used when the worker waits for tasks. */
  61. pthread_mutex_t *sched_mutex; /* mutex protecting sched_cond */
  62. struct starpu_task_list local_tasks; /* this queue contains tasks that have been explicitely submitted to that queue */
  63. struct starpu_worker_set_s *set; /* in case this worker belongs to a set */
  64. struct starpu_job_list_s *terminated_jobs; /* list of pending jobs which were executed */
  65. unsigned worker_is_running;
  66. unsigned worker_is_initialized;
  67. starpu_worker_status status; /* what is the worker doing now ? (eg. CALLBACK) */
  68. char name[32];
  69. #ifdef __GLIBC__
  70. cpu_set_t initial_cpu_set;
  71. cpu_set_t current_cpu_set;
  72. #endif /* __GLIBC__ */
  73. #ifdef STARPU_HAVE_HWLOC
  74. hwloc_cpuset_t initial_hwloc_cpu_set;
  75. hwloc_cpuset_t current_hwloc_cpu_set;
  76. #endif
  77. };
  78. struct starpu_combined_worker_s {
  79. enum starpu_perf_archtype perf_arch; /* in case there are different models of the same arch */
  80. uint32_t worker_mask; /* what is the type of workers ? */
  81. int worker_size;
  82. unsigned memory_node; /* which memory node is associated that worker to ? */
  83. int combined_workerid[STARPU_NMAXWORKERS];
  84. #ifdef __GLIBC__
  85. cpu_set_t cpu_set;
  86. #endif /* __GLIBC__ */
  87. #ifdef STARPU_HAVE_HWLOC
  88. hwloc_cpuset_t hwloc_cpu_set;
  89. #endif
  90. };
  91. /* in case a single CPU worker may control multiple
  92. * accelerators (eg. Gordon for n SPUs) */
  93. struct starpu_worker_set_s {
  94. pthread_mutex_t mutex;
  95. pthread_t worker_thread; /* the thread which runs the worker */
  96. unsigned nworkers;
  97. unsigned joined; /* only one thread may call pthread_join*/
  98. void *retval;
  99. struct starpu_worker_s *workers;
  100. pthread_cond_t ready_cond; /* indicate when the set is ready */
  101. unsigned set_is_initialized;
  102. };
  103. struct starpu_machine_config_s {
  104. struct starpu_machine_topology_s topology;
  105. #ifdef STARPU_HAVE_HWLOC
  106. int cpu_depth;
  107. #endif
  108. /* Where to bind workers ? */
  109. int current_bindid;
  110. /* Which GPU(s) do we use for CUDA ? */
  111. int current_cuda_gpuid;
  112. /* Which GPU(s) do we use for OpenCL ? */
  113. int current_opencl_gpuid;
  114. /* Basic workers : each of this worker is running its own driver and
  115. * can be combined with other basic workers. */
  116. struct starpu_worker_s workers[STARPU_NMAXWORKERS];
  117. /* Combined workers: these worker are a combination of basic workers
  118. * that can run parallel tasks together. */
  119. struct starpu_combined_worker_s combined_workers[STARPU_NMAX_COMBINEDWORKERS];
  120. /* This bitmask indicates which kinds of worker are available. For
  121. * instance it is possible to test if there is a CUDA worker with
  122. * the result of (worker_mask & STARPU_CUDA). */
  123. uint32_t worker_mask;
  124. /* in case the user gives an explicit configuration, this is only valid
  125. * during starpu_init. */
  126. struct starpu_conf *user_conf;
  127. /* this flag is set until the runtime is stopped */
  128. unsigned running;
  129. };
  130. /* Has starpu_shutdown already been called ? */
  131. unsigned _starpu_machine_is_running(void);
  132. /* Check if there is a worker that may execute the task. */
  133. uint32_t _starpu_worker_exists(uint32_t task_mask);
  134. /* Is there a worker that can execute CUDA code ? */
  135. uint32_t _starpu_may_submit_cuda_task(void);
  136. /* Is there a worker that can execute CPU code ? */
  137. uint32_t _starpu_may_submit_cpu_task(void);
  138. /* Is there a worker that can execute OpenCL code ? */
  139. uint32_t _starpu_may_submit_opencl_task(void);
  140. /* Check whether there is anything that the worker should do instead of
  141. * sleeping (waiting on something to happen). */
  142. unsigned _starpu_worker_can_block(unsigned memnode);
  143. /* This function must be called to block a worker. It puts the worker in a
  144. * sleeping state until there is some event that forces the worker to wake up.
  145. * */
  146. void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *mutex);
  147. /* The starpu_worker_s structure describes all the state of a StarPU worker.
  148. * This function sets the pthread key which stores a pointer to this structure.
  149. * */
  150. void _starpu_set_local_worker_key(struct starpu_worker_s *worker);
  151. /* Returns the starpu_worker_s structure that describes the state of the
  152. * current worker. */
  153. struct starpu_worker_s *_starpu_get_local_worker_key(void);
  154. /* Returns the starpu_worker_s structure that describes the state of the
  155. * specified worker. */
  156. struct starpu_worker_s *_starpu_get_worker_struct(unsigned id);
  157. struct starpu_combined_worker_s *_starpu_get_combined_worker_struct(unsigned id);
  158. /* Returns the structure that describes the overall machine configuration (eg.
  159. * all workers and topology). */
  160. struct starpu_machine_config_s *_starpu_get_machine_config(void);
  161. /* Retrieve the status which indicates what the worker is currently doing. */
  162. starpu_worker_status _starpu_worker_get_status(int workerid);
  163. /* Change the status of the worker which indicates what the worker is currently
  164. * doing (eg. executing a callback). */
  165. void _starpu_worker_set_status(int workerid, starpu_worker_status status);
  166. /* TODO move */
  167. unsigned _starpu_execute_registered_progression_hooks(void);
  168. #endif // __WORKERS_H__