workers.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <starpu.h>
  31. #ifdef USE_CUDA
  32. #include <drivers/cuda/driver_cuda.h>
  33. #endif
  34. #ifdef USE_GORDON
  35. #include <drivers/gordon/driver_gordon.h>
  36. #endif
  37. #include <drivers/core/driver_core.h>
  38. #include <datawizard/datawizard.h>
  39. #define CORE_ALPHA 1.0f
  40. #define CUDA_ALPHA 13.33f
  41. #define GORDON_ALPHA 6.0f /* XXX this is a random value ... */
  42. #define NMAXWORKERS 16
  43. #ifdef DATA_STATS
  44. #define BENCHMARK_COMM 1
  45. #else
  46. #define BENCHMARK_COMM 0
  47. #endif
  48. enum archtype {
  49. CORE_WORKER,
  50. CUDA_WORKER,
  51. GORDON_WORKER
  52. };
  53. struct worker_s {
  54. pthread_mutex_t mutex;
  55. enum archtype arch; /* 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 id; /* which core/gpu/etc is controlled by the workker ? */
  59. int bindid; /* which core is the driver bound to ? */
  60. pthread_cond_t ready_cond; /* indicate when the worker is ready */
  61. unsigned memory_node; /* which memory node is associated that worker to ? */
  62. struct jobq_s *jobq; /* in which queue will that worker get/put tasks ? */
  63. struct worker_set_s *set; /* in case this worker belongs to a set */
  64. struct job_list_s *terminated_jobs; /* list of pending jobs which were executed */
  65. unsigned worker_is_running;
  66. unsigned worker_is_initialized;
  67. };
  68. /* in case a single CPU worker may control multiple
  69. * accelerators (eg. Gordon for n SPUs) */
  70. struct worker_set_s {
  71. pthread_mutex_t mutex;
  72. pthread_t worker_thread; /* the thread which runs the worker */
  73. unsigned nworkers;
  74. unsigned joined; /* only one thread may call pthread_join*/
  75. void *retval;
  76. struct worker_s *workers;
  77. pthread_cond_t ready_cond; /* indicate when the set is ready */
  78. unsigned set_is_initialized;
  79. };
  80. struct machine_config_s {
  81. unsigned nworkers;
  82. struct worker_s workers[NMAXWORKERS];
  83. /* this flag is set until the runtime is stopped */
  84. unsigned running;
  85. };
  86. void terminate_workers(struct machine_config_s *config);
  87. void kill_all_workers(struct machine_config_s *config);
  88. void display_general_stats(void);
  89. unsigned machine_is_running(void);
  90. inline uint32_t worker_exists(uint32_t task_mask);
  91. inline uint32_t may_submit_cuda_task(void);
  92. inline uint32_t may_submit_core_task(void);
  93. #endif // __WORKERS_H__