openmp_runtime_support.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014 Inria
  4. *
  5. * StarPU 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. * StarPU 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 __OPENMP_RUNTIME_SUPPORT_H__
  17. #define __OPENMP_RUNTIME_SUPPORT_H__
  18. #include <starpu.h>
  19. #ifdef STARPU_OPENMP
  20. #include <common/list.h>
  21. #include <common/starpu_spinlock.h>
  22. /* ucontexts have been deprecated as of POSIX 1-2004
  23. * _XOPEN_SOURCE required at least on OS/X
  24. *
  25. * TODO: add detection in configure.ac
  26. */
  27. #ifndef _XOPEN_SOURCE
  28. #define _XOPEN_SOURCE
  29. #endif
  30. #include <ucontext.h>
  31. /*
  32. * Arbitrary limit on the number of nested parallel sections
  33. */
  34. #define STARPU_OMP_MAX_ACTIVE_LEVELS 4
  35. /*
  36. * Proc bind modes defined by the OpenMP spec
  37. */
  38. enum starpu_omp_bind_mode
  39. {
  40. starpu_omp_bind_false = 0,
  41. starpu_omp_bind_true = 1,
  42. starpu_omp_bind_master = 2,
  43. starpu_omp_bind_close = 3,
  44. starpu_omp_bind_spread = 4
  45. };
  46. enum starpu_omp_schedule_mode
  47. {
  48. starpu_omp_schedule_static = 0,
  49. starpu_omp_schedule_dynamic = 1,
  50. starpu_omp_schedule_guided = 2,
  51. starpu_omp_schedule_auto = 3
  52. };
  53. /*
  54. * Possible abstract names for OpenMP places
  55. */
  56. enum starpu_omp_place_name
  57. {
  58. starpu_omp_place_undefined = 0,
  59. starpu_omp_place_threads = 1,
  60. starpu_omp_place_cores = 2,
  61. starpu_omp_place_sockets = 3,
  62. starpu_omp_place_numerical = 4 /* place specified numerically */
  63. };
  64. struct starpu_omp_numeric_place
  65. {
  66. int excluded_place;
  67. int *included_numeric_items;
  68. int nb_included_numeric_items;
  69. int *excluded_numeric_items;
  70. int nb_excluded_numeric_items;
  71. };
  72. /*
  73. * OpenMP place for thread afinity, defined by the OpenMP spec
  74. */
  75. struct starpu_omp_place
  76. {
  77. int abstract_name;
  78. int abstract_excluded;
  79. int abstract_length;
  80. struct starpu_omp_numeric_place *numeric_places;
  81. int nb_numeric_places;
  82. };
  83. /*
  84. * Internal Control Variables (ICVs) declared following
  85. * OpenMP 4.0.0 spec section 2.3.1
  86. */
  87. struct starpu_omp_data_environment_icvs
  88. {
  89. /* parallel region icvs */
  90. int dyn_var;
  91. int nest_var;
  92. int *nthreads_var; /* nthreads_var ICV is a list */
  93. int thread_limit_var;
  94. int active_levels_var;
  95. int levels_var;
  96. int *bind_var; /* bind_var ICV is a list */
  97. /* loop region icvs */
  98. int run_sched_var;
  99. /* program execution icvs */
  100. int default_device_var;
  101. };
  102. struct starpu_omp_device_icvs
  103. {
  104. /* parallel region icvs */
  105. int max_active_levels_var;
  106. /* loop region icvs */
  107. int def_sched_var;
  108. /* program execution icvs */
  109. int stacksize_var;
  110. int wait_policy_var;
  111. };
  112. struct starpu_omp_implicit_task_icvs
  113. {
  114. /* parallel region icvs */
  115. int place_partition_var;
  116. };
  117. struct starpu_omp_global_icvs
  118. {
  119. /* program execution icvs */
  120. int cancel_var;
  121. };
  122. struct starpu_omp_initial_icv_values
  123. {
  124. int dyn_var;
  125. int nest_var;
  126. int *nthreads_var;
  127. int run_sched_var;
  128. int run_sched_chunk_var;
  129. int def_sched_var;
  130. int *bind_var;
  131. int stacksize_var;
  132. int wait_policy_var;
  133. int thread_limit_var;
  134. int max_active_levels_var;
  135. int active_levels_var;
  136. int levels_var;
  137. int place_partition_var;
  138. int cancel_var;
  139. int default_device_var;
  140. /* not a real ICV, but needed to store the contents of OMP_PLACES */
  141. struct starpu_omp_place places;
  142. };
  143. enum starpu_omp_task_state
  144. {
  145. starpu_omp_task_state_clear = 0,
  146. starpu_omp_task_state_preempted = 1,
  147. starpu_omp_task_state_terminated = 2,
  148. };
  149. LIST_TYPE(starpu_omp_task,
  150. struct starpu_omp_task *parent_task;
  151. struct starpu_omp_thread *owner_thread;
  152. struct starpu_omp_region *owner_region;
  153. struct starpu_omp_region *nested_region;
  154. int is_implicit;
  155. struct _starpu_spinlock lock;
  156. int barrier_count;
  157. int single_id;
  158. struct starpu_omp_data_environment_icvs data_env_icvs;
  159. struct starpu_omp_implicit_task_icvs implicit_task_icvs;
  160. struct starpu_task *starpu_task;
  161. void **starpu_buffers;
  162. void *starpu_cl_arg;
  163. /* actual task function to be run */
  164. void (*f)(void **starpu_buffers, void *starpu_cl_arg);
  165. enum starpu_omp_task_state state;
  166. /*
  167. * context to store the processing state of the task
  168. * in case of blocking/recursive task operation
  169. */
  170. ucontext_t ctx;
  171. /*
  172. * stack to execute the task over, to be able to switch
  173. * in case blocking/recursive task operation
  174. */
  175. void *stack;
  176. )
  177. LIST_TYPE(starpu_omp_thread,
  178. struct starpu_omp_task *current_task;
  179. struct starpu_omp_region *owner_region;
  180. struct starpu_omp_task *primary_task;
  181. /*
  182. * stack to execute the initial thread over
  183. * when preempting the initial task
  184. * note: should not be used for other threads
  185. */
  186. void *initial_thread_stack;
  187. /*
  188. * context to store the 'scheduler' state of the thread,
  189. * to which the execution of thread comes back upon a
  190. * blocking/recursive task operation
  191. */
  192. ucontext_t ctx;
  193. struct starpu_driver starpu_driver;
  194. unsigned starpu_worker_id;
  195. )
  196. struct starpu_omp_region
  197. {
  198. struct starpu_omp_region *parent_region;
  199. struct starpu_omp_device *owner_device;
  200. struct starpu_omp_thread *master_thread;
  201. /* note: the list of threads does not include the master_thread */
  202. struct starpu_omp_thread_list *thread_list;
  203. /* list of implicit omp tasks created to run the region */
  204. struct starpu_omp_task_list *implicit_task_list;
  205. /* include both the master thread and the region own threads */
  206. int nb_threads;
  207. int barrier_count;
  208. int single_id;
  209. int level;
  210. struct starpu_task *continuation_starpu_task;
  211. };
  212. struct starpu_omp_device
  213. {
  214. struct starpu_omp_device_icvs icvs;
  215. };
  216. struct starpu_omp_global
  217. {
  218. struct starpu_omp_global_icvs icvs;
  219. struct starpu_omp_task *initial_task;
  220. struct starpu_omp_thread *initial_thread;
  221. struct starpu_omp_region *initial_region;
  222. struct starpu_omp_device *initial_device;
  223. };
  224. /*
  225. * internal global variables
  226. */
  227. extern struct starpu_omp_initial_icv_values *_starpu_omp_initial_icv_values;
  228. extern struct starpu_omp_global *_starpu_omp_global_state;
  229. extern double _starpu_omp_clock_ref;
  230. /*
  231. * internal API
  232. */
  233. void _starpu_omp_environment_init(void);
  234. void _starpu_omp_environment_exit(void);
  235. #endif // STARPU_OPENMP
  236. #endif // __OPENMP_RUNTIME_SUPPORT_H__