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