openmp_runtime_support.h 6.0 KB

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