workers.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 HAVE_HWLOC
  34. #include <hwloc.h>
  35. #endif
  36. #ifdef USE_CUDA
  37. #include <drivers/cuda/driver_cuda.h>
  38. #endif
  39. #ifdef USE_GORDON
  40. #include <drivers/gordon/driver_gordon.h>
  41. #endif
  42. #include <drivers/core/driver_core.h>
  43. #include <datawizard/datawizard.h>
  44. #define CORE_ALPHA 1.0f
  45. #define CUDA_ALPHA 13.33f
  46. #define GORDON_ALPHA 6.0f /* XXX this is a random value ... */
  47. #ifdef DATA_STATS
  48. #define BENCHMARK_COMM 1
  49. #else
  50. #define BENCHMARK_COMM 0
  51. #endif
  52. struct worker_s {
  53. struct machine_config_s *config;
  54. pthread_mutex_t mutex;
  55. enum starpu_archtype arch; /* what is the type of worker ? */
  56. uint32_t worker_mask; /* what is the type of worker ? */
  57. enum starpu_perf_archtype perf_arch; /* in case there are different models of the same arch */
  58. pthread_t worker_thread; /* the thread which runs the worker */
  59. int id; /* which core/gpu/etc is controlled by the workker ? */
  60. int bindid; /* which core is the driver bound to ? */
  61. int workerid; /* uniquely identify the worker among all processing units types */
  62. pthread_cond_t ready_cond; /* indicate when the worker is ready */
  63. unsigned memory_node; /* which memory node is associated that worker to ? */
  64. struct jobq_s *jobq; /* in which queue will that worker get/put tasks ? */
  65. struct job_list_s *local_jobs; /* this queue contains tasks that have been explicitely submitted to that queue */
  66. pthread_mutex_t local_jobs_mutex; /* protect the local_jobs list */
  67. struct worker_set_s *set; /* in case this worker belongs to a set */
  68. struct job_list_s *terminated_jobs; /* list of pending jobs which were executed */
  69. unsigned worker_is_running;
  70. unsigned worker_is_initialized;
  71. worker_status status; /* what is the worker doing now ? (eg. CALLBACK) */
  72. char name[32];
  73. };
  74. /* in case a single CPU worker may control multiple
  75. * accelerators (eg. Gordon for n SPUs) */
  76. struct worker_set_s {
  77. pthread_mutex_t mutex;
  78. pthread_t worker_thread; /* the thread which runs the worker */
  79. unsigned nworkers;
  80. unsigned joined; /* only one thread may call pthread_join*/
  81. void *retval;
  82. struct worker_s *workers;
  83. pthread_cond_t ready_cond; /* indicate when the set is ready */
  84. unsigned set_is_initialized;
  85. };
  86. struct machine_config_s {
  87. unsigned nworkers;
  88. #ifdef HAVE_HWLOC
  89. hwloc_topology_t hwtopology;
  90. int core_depth;
  91. #endif
  92. unsigned nhwcores;
  93. unsigned ncores;
  94. unsigned ncudagpus;
  95. unsigned ngordon_spus;
  96. /* Where to bind workers ? */
  97. int current_bindid;
  98. unsigned workers_bindid[STARPU_NMAXWORKERS];
  99. /* Which GPU(s) do we use ? */
  100. int current_gpuid;
  101. unsigned workers_gpuid[STARPU_NMAXWORKERS];
  102. struct worker_s workers[STARPU_NMAXWORKERS];
  103. uint32_t worker_mask;
  104. struct starpu_topo_obj_t *topology;
  105. /* in case the user gives an explicit configuration, this is only valid
  106. * during starpu_init. */
  107. struct starpu_conf *user_conf;
  108. /* this flag is set until the runtime is stopped */
  109. unsigned running;
  110. };
  111. void display_general_stats(void);
  112. unsigned machine_is_running(void);
  113. inline uint32_t worker_exists(uint32_t task_mask);
  114. inline uint32_t may_submit_cuda_task(void);
  115. inline uint32_t may_submit_core_task(void);
  116. inline uint32_t worker_may_execute_task(unsigned workerid, uint32_t where);
  117. void bind_thread_on_cpu(struct machine_config_s *config, unsigned coreid);
  118. inline void lock_all_queues_attached_to_node(unsigned node);
  119. inline void unlock_all_queues_attached_to_node(unsigned node);
  120. inline void broadcast_all_queues_attached_to_node(unsigned node);
  121. void set_local_worker_key(struct worker_s *worker);
  122. struct worker_s *get_local_worker_key(void);
  123. struct worker_s *get_worker_struct(unsigned id);
  124. #endif // __WORKERS_H__