StarPU Internal Handbook

openmp_runtime_support.h
Go to the documentation of this file.
1/* StarPU --- Runtime system for heterogeneous multicore architectures.
2 *
3 * Copyright (C) 2014-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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
17#ifndef __OPENMP_RUNTIME_SUPPORT_H__
18#define __OPENMP_RUNTIME_SUPPORT_H__
19
22#include <starpu.h>
23
24#ifdef STARPU_OPENMP
25#include <common/list.h>
26#include <common/starpu_spinlock.h>
27#include <common/uthash.h>
28
34#ifndef _XOPEN_SOURCE
35#define _XOPEN_SOURCE
36#endif
37#include <ucontext.h>
38
39 extern starpu_pthread_key_t omp_thread_key;
40 extern starpu_pthread_key_t omp_task_key;
41
45#define STARPU_OMP_MAX_ACTIVE_LEVELS 1
46
50 enum starpu_omp_place_name
51{
52 starpu_omp_place_undefined = 0,
53 starpu_omp_place_threads = 1,
54 starpu_omp_place_cores = 2,
55 starpu_omp_place_sockets = 3,
56 starpu_omp_place_numerical = 4
57};
58
59 struct starpu_omp_numeric_place
60{
61 int excluded_place;
62 int *included_numeric_items;
63 int nb_included_numeric_items;
64 int *excluded_numeric_items;
65 int nb_excluded_numeric_items;
66};
67
71 struct starpu_omp_place
72{
73 int abstract_name;
74 int abstract_excluded;
75 int abstract_length;
76 struct starpu_omp_numeric_place *numeric_places;
77 int nb_numeric_places;
78};
79
84 struct starpu_omp_data_environment_icvs
85{
87 int dyn_var;
88 int nest_var;
89 int *nthreads_var;
90 int thread_limit_var;
91
92 int active_levels_var;
93 int levels_var;
94 int *bind_var;
97 int run_sched_var;
98 unsigned long long run_sched_chunk_var;
99
101 int default_device_var;
102 int max_task_priority_var;
103};
104
105 struct starpu_omp_device_icvs
106{
108 int max_active_levels_var;
109
111 int def_sched_var;
112 unsigned long long def_sched_chunk_var;
113
115 int stacksize_var;
116 int wait_policy_var;
117};
118
119 struct starpu_omp_implicit_task_icvs
120{
122 int place_partition_var;
123};
124
125 struct starpu_omp_global_icvs
126{
128 int cancel_var;
129};
130
131 struct starpu_omp_initial_icv_values
132{
133 int dyn_var;
134 int nest_var;
135 int *nthreads_var;
136 int run_sched_var;
137 unsigned long long run_sched_chunk_var;
138 int def_sched_var;
139 unsigned long long def_sched_chunk_var;
140 int *bind_var;
141 int stacksize_var;
142 int wait_policy_var;
143 int thread_limit_var;
144 int max_active_levels_var;
145 int active_levels_var;
146 int levels_var;
147 int place_partition_var;
148 int cancel_var;
149 int default_device_var;
150 int max_task_priority_var;
151
153 struct starpu_omp_place places;
154};
155
156 struct starpu_omp_task_group
157{
158 int descendent_task_count;
159 struct starpu_omp_task *leader_task;
160 struct starpu_omp_task_group *p_previous_task_group;
161};
162
163 struct starpu_omp_task_link
164{
165 struct starpu_omp_task *task;
166 struct starpu_omp_task_link *next;
167};
168
169 struct starpu_omp_condition
170{
171 struct starpu_omp_task_link *contention_list_head;
172};
173
174 struct starpu_omp_critical
175{
176 UT_hash_handle hh;
177 struct _starpu_spinlock lock;
178 unsigned state;
179 struct starpu_omp_task_link *contention_list_head;
180 const char *name;
181};
182
183 enum starpu_omp_task_state
184{
185 starpu_omp_task_state_clear = 0,
186 starpu_omp_task_state_preempted = 1,
187 starpu_omp_task_state_terminated = 2,
188 starpu_omp_task_state_zombie = 3,
189
191 starpu_omp_task_state_target = 4,
192};
193
194 enum starpu_omp_task_wait_on
195{
196 starpu_omp_task_wait_on_task_childs = 1 << 0,
197 starpu_omp_task_wait_on_region_tasks = 1 << 1,
198 starpu_omp_task_wait_on_barrier = 1 << 2,
199 starpu_omp_task_wait_on_group = 1 << 3,
200 starpu_omp_task_wait_on_critical = 1 << 4,
201 starpu_omp_task_wait_on_ordered = 1 << 5,
202 starpu_omp_task_wait_on_lock = 1 << 6,
203 starpu_omp_task_wait_on_nest_lock = 1 << 7,
204};
205
206 enum starpu_omp_task_flags
207{
208 STARPU_OMP_TASK_FLAGS_IMPLICIT = 1 << 0,
209 STARPU_OMP_TASK_FLAGS_UNDEFERRED = 1 << 1,
210 STARPU_OMP_TASK_FLAGS_FINAL = 1 << 2,
211 STARPU_OMP_TASK_FLAGS_UNTIED = 1 << 3,
212};
213
214LIST_TYPE(starpu_omp_task,
215 struct starpu_omp_implicit_task_icvs icvs;
216 struct starpu_omp_task *parent_task;
217 struct starpu_omp_thread *owner_thread;
218 struct starpu_omp_region *owner_region;
219 struct starpu_omp_region *nested_region;
220 int rank;
221 int child_task_count;
222 struct starpu_omp_task_group *task_group;
223 struct _starpu_spinlock lock;
224 int transaction_pending;
225 int wait_on;
226 int barrier_count;
227 int single_id;
228 int single_first;
229 int loop_id;
230 unsigned long long ordered_first_i;
231 unsigned long long ordered_nb_i;
232 int sections_id;
233 struct starpu_omp_data_environment_icvs data_env_icvs;
234 struct starpu_omp_implicit_task_icvs implicit_task_icvs;
235 struct handle_entry *registered_handles;
236
237 struct starpu_task *starpu_task;
238 struct starpu_codelet cl;
239 void **starpu_buffers;
240 void *starpu_cl_arg;
241
243 void (*cpu_f)(void **starpu_buffers, void *starpu_cl_arg);
244#ifdef STARPU_USE_CUDA
245 void (*cuda_f)(void **starpu_buffers, void *starpu_cl_arg);
246#endif
247#ifdef STARPU_USE_OPENCL
248 void (*opencl_f)(void **starpu_buffers, void *starpu_cl_arg);
249#endif
250
251 enum starpu_omp_task_state state;
252 enum starpu_omp_task_flags flags;
253
254 /*
255 * context to store the processing state of the task
256 * in case of blocking/recursive task operation
257 */
258 ucontext_t ctx;
259
260 /*
261 * stack to execute the task over, to be able to switch
262 * in case blocking/recursive task operation
263 */
264 void *stack;
265
266 /*
267 * Valgrind stack id
268 */
269 int stack_vg_id;
270
271 size_t stacksize;
272
273 /*
274 * taskloop attribute
275 * */
276 int is_loop;
277 unsigned long long nb_iterations;
278 unsigned long long grainsize;
279 unsigned long long chunk;
280 unsigned long long begin_i;
281 unsigned long long end_i;
282)
283
284LIST_TYPE(starpu_omp_thread,
285
286 UT_hash_handle hh;
287 struct starpu_omp_task *current_task;
288 struct starpu_omp_region *owner_region;
289
290 /*
291 * stack to execute the initial thread over
292 * when preempting the initial task
293 * note: should not be used for other threads
294 */
295 void *initial_thread_stack;
296 /*
297 * Valgrind stack id
298 */
299 int initial_thread_stack_vg_id;
300
301 /*
302 * context to store the 'scheduler' state of the thread,
303 * to which the execution of thread comes back upon a
304 * blocking/recursive task operation
305 */
306 ucontext_t ctx;
307
308 struct starpu_driver starpu_driver;
309 struct _starpu_worker *worker;
310)
311
312 struct _starpu_omp_lock_internal
313{
314 struct _starpu_spinlock lock;
315 struct starpu_omp_condition cond;
316 unsigned state;
317};
318
319 struct _starpu_omp_nest_lock_internal
320{
321 struct _starpu_spinlock lock;
322 struct starpu_omp_condition cond;
323 unsigned state;
324 struct starpu_omp_task *owner_task;
325 unsigned nesting;
326};
327
328 struct starpu_omp_loop
329{
330 int id;
331 unsigned long long next_iteration;
332 int nb_completed_threads;
333 struct starpu_omp_loop *next_loop;
334 struct _starpu_spinlock ordered_lock;
335 struct starpu_omp_condition ordered_cond;
336 unsigned long long ordered_iteration;
337};
338
339 struct starpu_omp_sections
340{
341 int id;
342 unsigned long long next_section_num;
343 int nb_completed_threads;
344 struct starpu_omp_sections *next_sections;
345};
346
347 struct starpu_omp_region
348{
349 struct starpu_omp_data_environment_icvs icvs;
350 struct starpu_omp_region *parent_region;
351 struct starpu_omp_device *owner_device;
352 struct starpu_omp_thread *master_thread;
354 struct starpu_omp_thread_list thread_list;
356 struct starpu_omp_task **implicit_task_array;
358 int nb_threads;
359 struct _starpu_spinlock lock;
360 struct starpu_omp_task *waiting_task;
361 int barrier_count;
362 int bound_explicit_task_count;
363 int single_id;
364 void *copy_private_data;
365 int level;
366 struct starpu_omp_loop *loop_list;
367 struct starpu_omp_sections *sections_list;
368 struct starpu_task *continuation_starpu_task;
369 struct handle_entry *registered_handles;
370 struct _starpu_spinlock registered_handles_lock;
371};
372
373 struct starpu_omp_device
374{
375 struct starpu_omp_device_icvs icvs;
376
378 struct _starpu_spinlock atomic_lock;
379};
380
381 struct starpu_omp_global
382{
383 struct starpu_omp_global_icvs icvs;
384 struct starpu_omp_task *initial_task;
385 struct starpu_omp_thread *initial_thread;
386 struct starpu_omp_region *initial_region;
387 struct starpu_omp_device *initial_device;
388 struct starpu_omp_critical *default_critical;
389 struct starpu_omp_critical *named_criticals;
390 struct _starpu_spinlock named_criticals_lock;
391 struct starpu_omp_thread *hash_workers;
392 struct _starpu_spinlock hash_workers_lock;
393 struct starpu_arbiter *default_arbiter;
394 unsigned nb_starpu_cpu_workers;
395 int *starpu_cpu_worker_ids;
396 int environment_valid;
397};
398
399/*
400 * internal global variables
401 */
402 extern struct starpu_omp_initial_icv_values *_starpu_omp_initial_icv_values;
403 extern struct starpu_omp_global *_starpu_omp_global_state;
404 extern double _starpu_omp_clock_ref;
405
406/*
407 * internal API
408 */
409 void _starpu_omp_environment_init(void);
410 void _starpu_omp_environment_exit(void);
411 int _starpu_omp_environment_check(void);
412 struct starpu_omp_thread *_starpu_omp_get_thread(void);
413 struct starpu_omp_region *_starpu_omp_get_region_at_level(int level);
414 struct starpu_omp_task *_starpu_omp_get_task(void);
415 int _starpu_omp_get_region_thread_num(const struct starpu_omp_region *const region);
416 void _starpu_omp_dummy_init(void);
417 void _starpu_omp_dummy_shutdown(void);
418#endif // STARPU_OPENMP
419
420#endif // __OPENMP_RUNTIME_SUPPORT_H__
list.h
starpu_omp_device_icvs::def_sched_var
int def_sched_var
Definition: openmp_runtime_support.h:111
starpu_omp_data_environment_icvs::run_sched_var
int run_sched_var
Definition: openmp_runtime_support.h:97
starpu_omp_place_name
starpu_omp_place_name
Definition: openmp_runtime_support.h:51
starpu_omp_data_environment_icvs::thread_limit_var
int thread_limit_var
Definition: openmp_runtime_support.h:90
starpu_omp_implicit_task_icvs::place_partition_var
int place_partition_var
Definition: openmp_runtime_support.h:122
starpu_omp_device_icvs::max_active_levels_var
int max_active_levels_var
Definition: openmp_runtime_support.h:108
starpu_omp_device_icvs::stacksize_var
int stacksize_var
Definition: openmp_runtime_support.h:115
starpu_omp_task_state
starpu_omp_task_state
Definition: openmp_runtime_support.h:184
starpu_omp_task_state_target
@ starpu_omp_task_state_target
Definition: openmp_runtime_support.h:191
starpu_omp_initial_icv_values::places
struct starpu_omp_place places
Definition: openmp_runtime_support.h:153
starpu_omp_data_environment_icvs::dyn_var
int dyn_var
Definition: openmp_runtime_support.h:87
starpu_omp_data_environment_icvs::default_device_var
int default_device_var
Definition: openmp_runtime_support.h:101
starpu_omp_global_icvs::cancel_var
int cancel_var
Definition: openmp_runtime_support.h:128
starpu_omp_condition
Definition: openmp_runtime_support.h:170
starpu_omp_critical
Definition: openmp_runtime_support.h:175
starpu_omp_data_environment_icvs
Definition: openmp_runtime_support.h:85
starpu_omp_device_icvs
Definition: openmp_runtime_support.h:106
starpu_omp_global_icvs
Definition: openmp_runtime_support.h:126
starpu_omp_implicit_task_icvs
Definition: openmp_runtime_support.h:120
starpu_omp_initial_icv_values
Definition: openmp_runtime_support.h:132
starpu_omp_numeric_place
Definition: openmp_runtime_support.h:60
starpu_omp_place
Definition: openmp_runtime_support.h:72
starpu_omp_task_group
Definition: openmp_runtime_support.h:157
starpu_omp_task_link
Definition: openmp_runtime_support.h:164
starpu_spinlock.h
_starpu_spinlock
Definition: starpu_spinlock.h:82
_starpu_worker
Definition: workers.h:70
uthash.h
UT_hash_handle
Definition: uthash.h:1015