workers.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2009 (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 <common/config.h>
  20. #include <pthread.h>
  21. #include <common/timing.h>
  22. #include <common/fxt.h>
  23. #include <core/jobs.h>
  24. #include <core/perfmodel/perfmodel.h>
  25. #include <core/policies/sched_policy.h>
  26. #include <core/topology.h>
  27. #include <core/errorcheck.h>
  28. #ifdef STARPU_HAVE_HWLOC
  29. #include <hwloc.h>
  30. #endif
  31. #ifdef STARPU_USE_CUDA
  32. #include <drivers/cuda/driver_cuda.h>
  33. #endif
  34. #ifdef STARPU_USE_OPENCL
  35. #include <drivers/opencl/driver_opencl.h>
  36. #endif
  37. #ifdef STARPU_USE_GORDON
  38. #include <drivers/gordon/driver_gordon.h>
  39. #endif
  40. #include <drivers/cpu/driver_cpu.h>
  41. #include <datawizard/datawizard.h>
  42. #define STARPU_CPU_ALPHA 1.0f
  43. #define STARPU_CUDA_ALPHA 13.33f
  44. #define STARPU_OPENCL_ALPHA 12.22f
  45. #define STARPU_GORDON_ALPHA 6.0f /* XXX this is a random value ... */
  46. #ifdef STARPU_DATA_STATS
  47. #define STARPU_BENCHMARK_COMM 1
  48. #else
  49. #define STARPU_BENCHMARK_COMM 0
  50. #endif
  51. struct starpu_worker_s {
  52. struct starpu_machine_config_s *config;
  53. pthread_mutex_t mutex;
  54. enum starpu_archtype arch; /* what is the type of worker ? */
  55. uint32_t worker_mask; /* what is the type of worker ? */
  56. enum starpu_perf_archtype perf_arch; /* in case there are different models of the same arch */
  57. pthread_t worker_thread; /* the thread which runs the worker */
  58. int devid; /* which cpu/gpu/etc is controlled by the workker ? */
  59. int bindid; /* which cpu is the driver bound to ? */
  60. int workerid; /* uniquely identify the worker among all processing units types */
  61. pthread_cond_t ready_cond; /* indicate when the worker is ready */
  62. unsigned memory_node; /* which memory node is associated that worker to ? */
  63. struct starpu_jobq_s *jobq; /* in which queue will that worker get/put tasks ? */
  64. struct starpu_job_list_s *local_jobs; /* this queue contains tasks that have been explicitely submitted to that queue */
  65. pthread_mutex_t local_jobs_mutex; /* protect the local_jobs list */
  66. struct starpu_worker_set_s *set; /* in case this worker belongs to a set */
  67. struct starpu_job_list_s *terminated_jobs; /* list of pending jobs which were executed */
  68. unsigned worker_is_running;
  69. unsigned worker_is_initialized;
  70. starpu_worker_status status; /* what is the worker doing now ? (eg. CALLBACK) */
  71. char name[32];
  72. };
  73. /* in case a single CPU worker may control multiple
  74. * accelerators (eg. Gordon for n SPUs) */
  75. struct starpu_worker_set_s {
  76. pthread_mutex_t mutex;
  77. pthread_t worker_thread; /* the thread which runs the worker */
  78. unsigned nworkers;
  79. unsigned joined; /* only one thread may call pthread_join*/
  80. void *retval;
  81. struct starpu_worker_s *workers;
  82. pthread_cond_t ready_cond; /* indicate when the set is ready */
  83. unsigned set_is_initialized;
  84. };
  85. struct starpu_machine_config_s {
  86. unsigned nworkers;
  87. #ifdef STARPU_HAVE_HWLOC
  88. hwloc_topology_t hwtopology;
  89. int cpu_depth;
  90. #endif
  91. unsigned nhwcpus;
  92. unsigned nhwcudagpus;
  93. unsigned nhwopenclgpus;
  94. unsigned ncpus;
  95. unsigned ncudagpus;
  96. unsigned nopenclgpus;
  97. unsigned ngordon_spus;
  98. /* Where to bind workers ? */
  99. int current_bindid;
  100. unsigned workers_bindid[STARPU_NMAXWORKERS];
  101. /* Which GPU(s) do we use for CUDA ? */
  102. int current_cuda_gpuid;
  103. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  104. /* Which GPU(s) do we use for OpenCL ? */
  105. int current_opencl_gpuid;
  106. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  107. struct starpu_worker_s workers[STARPU_NMAXWORKERS];
  108. /* This bitmask indicates which kinds of worker are available. For
  109. * instance it is possible to test if there is a CUDA worker with
  110. * the result of (worker_mask & STARPU_CUDA). */
  111. uint32_t worker_mask;
  112. /* in case the user gives an explicit configuration, this is only valid
  113. * during starpu_init. */
  114. struct starpu_conf *user_conf;
  115. /* this flag is set until the runtime is stopped */
  116. unsigned running;
  117. };
  118. unsigned _starpu_machine_is_running(void);
  119. uint32_t _starpu_worker_exists(uint32_t task_mask);
  120. uint32_t _starpu_may_submit_cuda_task(void);
  121. uint32_t _starpu_may_submit_cpu_task(void);
  122. uint32_t _starpu_may_submit_opencl_task(void);
  123. uint32_t _starpu_worker_may_execute_task(unsigned workerid, uint32_t where);
  124. unsigned _starpu_worker_can_block(unsigned memnode);
  125. void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *mutex);
  126. void _starpu_lock_all_queues_attached_to_node(unsigned node);
  127. void _starpu_unlock_all_queues_attached_to_node(unsigned node);
  128. void _starpu_broadcast_all_queues_attached_to_node(unsigned node);
  129. void _starpu_set_local_worker_key(struct starpu_worker_s *worker);
  130. struct starpu_worker_s *_starpu_get_local_worker_key(void);
  131. struct starpu_worker_s *_starpu_get_worker_struct(unsigned id);
  132. struct starpu_machine_config_s *_starpu_get_machine_config(void);
  133. starpu_worker_status _starpu_worker_get_status(int workerid);
  134. void _starpu_worker_set_status(int workerid, starpu_worker_status status);
  135. /* TODO move */
  136. unsigned _starpu_execute_registered_progression_hooks(void);
  137. #endif // __WORKERS_H__