workers.h 5.5 KB

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