workers.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __WORKERS_H__
  17. #define __WORKERS_H__
  18. #include <starpu.h>
  19. #include <starpu_scheduler.h>
  20. #include <common/config.h>
  21. #include <pthread.h>
  22. #include <common/timing.h>
  23. #include <common/fxt.h>
  24. #include <core/jobs.h>
  25. #include <core/perfmodel/perfmodel.h>
  26. #include <core/sched_policy.h>
  27. #include <core/topology.h>
  28. #include <core/errorcheck.h>
  29. #ifdef STARPU_HAVE_HWLOC
  30. #include <hwloc.h>
  31. #endif
  32. #ifdef STARPU_USE_CUDA
  33. #include <drivers/cuda/driver_cuda.h>
  34. #endif
  35. #ifdef STARPU_USE_OPENCL
  36. #include <drivers/opencl/driver_opencl.h>
  37. #endif
  38. #ifdef STARPU_USE_GORDON
  39. #include <drivers/gordon/driver_gordon.h>
  40. #endif
  41. #include <drivers/cpu/driver_cpu.h>
  42. #include <datawizard/datawizard.h>
  43. #define STARPU_CPU_ALPHA 1.0f
  44. #define STARPU_CUDA_ALPHA 13.33f
  45. #define STARPU_OPENCL_ALPHA 12.22f
  46. #define STARPU_GORDON_ALPHA 6.0f /* XXX this is a random value ... */
  47. struct starpu_worker_s {
  48. struct starpu_machine_config_s *config;
  49. pthread_mutex_t mutex;
  50. enum starpu_archtype arch; /* what is the type of worker ? */
  51. uint32_t worker_mask; /* what is the type of worker ? */
  52. enum starpu_perf_archtype perf_arch; /* in case there are different models of the same arch */
  53. pthread_t worker_thread; /* the thread which runs the worker */
  54. int devid; /* which cpu/gpu/etc is controlled by the workker ? */
  55. int bindid; /* which cpu is the driver bound to ? */
  56. int workerid; /* uniquely identify the worker among all processing units types */
  57. pthread_cond_t ready_cond; /* indicate when the worker is ready */
  58. unsigned memory_node; /* which memory node is associated that worker to ? */
  59. pthread_cond_t *sched_cond; /* condition variable used when the worker waits for tasks. */
  60. pthread_mutex_t *sched_mutex; /* mutex protecting sched_cond */
  61. struct starpu_job_list_s *local_jobs; /* this queue contains tasks that have been explicitely submitted to that queue */
  62. pthread_mutex_t local_jobs_mutex; /* protect the local_jobs list */
  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. };
  70. /* in case a single CPU worker may control multiple
  71. * accelerators (eg. Gordon for n SPUs) */
  72. struct starpu_worker_set_s {
  73. pthread_mutex_t mutex;
  74. pthread_t worker_thread; /* the thread which runs the worker */
  75. unsigned nworkers;
  76. unsigned joined; /* only one thread may call pthread_join*/
  77. void *retval;
  78. struct starpu_worker_s *workers;
  79. pthread_cond_t ready_cond; /* indicate when the set is ready */
  80. unsigned set_is_initialized;
  81. };
  82. struct starpu_machine_config_s {
  83. struct starpu_machine_topology_s topology;
  84. #ifdef STARPU_HAVE_HWLOC
  85. int cpu_depth;
  86. #endif
  87. /* Where to bind workers ? */
  88. int current_bindid;
  89. /* Which GPU(s) do we use for CUDA ? */
  90. int current_cuda_gpuid;
  91. /* Which GPU(s) do we use for OpenCL ? */
  92. int current_opencl_gpuid;
  93. struct starpu_worker_s workers[STARPU_NMAXWORKERS];
  94. /* This bitmask indicates which kinds of worker are available. For
  95. * instance it is possible to test if there is a CUDA worker with
  96. * the result of (worker_mask & STARPU_CUDA). */
  97. uint32_t worker_mask;
  98. /* in case the user gives an explicit configuration, this is only valid
  99. * during starpu_init. */
  100. struct starpu_conf *user_conf;
  101. /* this flag is set until the runtime is stopped */
  102. unsigned running;
  103. };
  104. /* Has starpu_shutdown already been called ? */
  105. unsigned _starpu_machine_is_running(void);
  106. /* Check if there is a worker that may execute the task. */
  107. uint32_t _starpu_worker_exists(uint32_t task_mask);
  108. /* Is there a worker that can execute CUDA code ? */
  109. uint32_t _starpu_may_submit_cuda_task(void);
  110. /* Is there a worker that can execute CPU code ? */
  111. uint32_t _starpu_may_submit_cpu_task(void);
  112. /* Is there a worker that can execute OpenCL code ? */
  113. uint32_t _starpu_may_submit_opencl_task(void);
  114. /* Check if the worker specified by workerid can execute the codelet. */
  115. int _starpu_worker_may_execute_task(unsigned workerid, struct starpu_task *task);
  116. /* Check whether there is anything that the worker should do instead of
  117. * sleeping (waiting on something to happen). */
  118. unsigned _starpu_worker_can_block(unsigned memnode);
  119. /* This function must be called to block a worker. It puts the worker in a
  120. * sleeping state until there is some event that forces the worker to wake up.
  121. * */
  122. void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *mutex);
  123. /* The starpu_worker_s structure describes all the state of a StarPU worker.
  124. * This function sets the pthread key which stores a pointer to this structure.
  125. * */
  126. void _starpu_set_local_worker_key(struct starpu_worker_s *worker);
  127. /* Returns the starpu_worker_s structure that describes the state of the
  128. * current worker. */
  129. struct starpu_worker_s *_starpu_get_local_worker_key(void);
  130. /* Returns the starpu_worker_s structure that describes the state of the
  131. * specified worker. */
  132. struct starpu_worker_s *_starpu_get_worker_struct(unsigned id);
  133. /* Returns the structure that describes the overall machine configuration (eg.
  134. * all workers and topology). */
  135. struct starpu_machine_config_s *_starpu_get_machine_config(void);
  136. /* Retrieve the status which indicates what the worker is currently doing. */
  137. starpu_worker_status _starpu_worker_get_status(int workerid);
  138. /* Change the status of the worker which indicates what the worker is currently
  139. * doing (eg. executing a callback). */
  140. void _starpu_worker_set_status(int workerid, starpu_worker_status status);
  141. /* TODO move */
  142. unsigned _starpu_execute_registered_progression_hooks(void);
  143. #endif // __WORKERS_H__