xref: /freebsd/lib/libomp/omp.h (revision 732a02b4e77866604a120a275c082bb6221bd2ff)
1 // $FreeBSD$
2 /*
3  * include/omp.h.var
4  */
5 
6 
7 //===----------------------------------------------------------------------===//
8 //
9 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10 // See https://llvm.org/LICENSE.txt for license information.
11 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12 //
13 //===----------------------------------------------------------------------===//
14 
15 
16 #ifndef __OMP_H
17 #   define __OMP_H
18 
19 #   include <stdlib.h>
20 #   include <stdint.h>
21 
22 #   define KMP_VERSION_MAJOR    5
23 #   define KMP_VERSION_MINOR    0
24 #   define KMP_VERSION_BUILD    20140926
25 #   define KMP_BUILD_DATE       "No_Timestamp"
26 
27 #   ifdef __cplusplus
28     extern "C" {
29 #   endif
30 
31 #   define omp_set_affinity_format   ompc_set_affinity_format
32 #   define omp_get_affinity_format   ompc_get_affinity_format
33 #   define omp_display_affinity      ompc_display_affinity
34 #   define omp_capture_affinity      ompc_capture_affinity
35 
36 #   if defined(_WIN32)
37 #       define __KAI_KMPC_CONVENTION __cdecl
38 #       ifndef __KMP_IMP
39 #           define __KMP_IMP __declspec(dllimport)
40 #       endif
41 #   else
42 #       define __KAI_KMPC_CONVENTION
43 #       ifndef __KMP_IMP
44 #           define __KMP_IMP
45 #       endif
46 #   endif
47 
48     /* schedule kind constants */
49     typedef enum omp_sched_t {
50         omp_sched_static  = 1,
51         omp_sched_dynamic = 2,
52         omp_sched_guided  = 3,
53         omp_sched_auto    = 4,
54         omp_sched_monotonic = 0x80000000
55     } omp_sched_t;
56 
57     /* set API functions */
58     extern void   __KAI_KMPC_CONVENTION  omp_set_num_threads (int);
59     extern void   __KAI_KMPC_CONVENTION  omp_set_dynamic     (int);
60     extern void   __KAI_KMPC_CONVENTION  omp_set_nested      (int);
61     extern void   __KAI_KMPC_CONVENTION  omp_set_max_active_levels (int);
62     extern void   __KAI_KMPC_CONVENTION  omp_set_schedule          (omp_sched_t, int);
63 
64     /* query API functions */
65     extern int    __KAI_KMPC_CONVENTION  omp_get_num_threads  (void);
66     extern int    __KAI_KMPC_CONVENTION  omp_get_dynamic      (void);
67     extern int    __KAI_KMPC_CONVENTION  omp_get_nested       (void);
68     extern int    __KAI_KMPC_CONVENTION  omp_get_max_threads  (void);
69     extern int    __KAI_KMPC_CONVENTION  omp_get_thread_num   (void);
70     extern int    __KAI_KMPC_CONVENTION  omp_get_num_procs    (void);
71     extern int    __KAI_KMPC_CONVENTION  omp_in_parallel      (void);
72     extern int    __KAI_KMPC_CONVENTION  omp_in_final         (void);
73     extern int    __KAI_KMPC_CONVENTION  omp_get_active_level        (void);
74     extern int    __KAI_KMPC_CONVENTION  omp_get_level               (void);
75     extern int    __KAI_KMPC_CONVENTION  omp_get_ancestor_thread_num (int);
76     extern int    __KAI_KMPC_CONVENTION  omp_get_team_size           (int);
77     extern int    __KAI_KMPC_CONVENTION  omp_get_thread_limit        (void);
78     extern int    __KAI_KMPC_CONVENTION  omp_get_max_active_levels   (void);
79     extern void   __KAI_KMPC_CONVENTION  omp_get_schedule            (omp_sched_t *, int *);
80     extern int    __KAI_KMPC_CONVENTION  omp_get_max_task_priority   (void);
81 
82     /* lock API functions */
83     typedef struct omp_lock_t {
84         void * _lk;
85     } omp_lock_t;
86 
87     extern void   __KAI_KMPC_CONVENTION  omp_init_lock    (omp_lock_t *);
88     extern void   __KAI_KMPC_CONVENTION  omp_set_lock     (omp_lock_t *);
89     extern void   __KAI_KMPC_CONVENTION  omp_unset_lock   (omp_lock_t *);
90     extern void   __KAI_KMPC_CONVENTION  omp_destroy_lock (omp_lock_t *);
91     extern int    __KAI_KMPC_CONVENTION  omp_test_lock    (omp_lock_t *);
92 
93     /* nested lock API functions */
94     typedef struct omp_nest_lock_t {
95         void * _lk;
96     } omp_nest_lock_t;
97 
98     extern void   __KAI_KMPC_CONVENTION  omp_init_nest_lock    (omp_nest_lock_t *);
99     extern void   __KAI_KMPC_CONVENTION  omp_set_nest_lock     (omp_nest_lock_t *);
100     extern void   __KAI_KMPC_CONVENTION  omp_unset_nest_lock   (omp_nest_lock_t *);
101     extern void   __KAI_KMPC_CONVENTION  omp_destroy_nest_lock (omp_nest_lock_t *);
102     extern int    __KAI_KMPC_CONVENTION  omp_test_nest_lock    (omp_nest_lock_t *);
103 
104     /* OpenMP 5.0  Synchronization hints*/
105     typedef enum omp_sync_hint_t {
106         omp_sync_hint_none           = 0,
107         omp_lock_hint_none           = omp_sync_hint_none,
108         omp_sync_hint_uncontended    = 1,
109         omp_lock_hint_uncontended    = omp_sync_hint_uncontended,
110         omp_sync_hint_contended      = (1<<1),
111         omp_lock_hint_contended      = omp_sync_hint_contended,
112         omp_sync_hint_nonspeculative = (1<<2),
113         omp_lock_hint_nonspeculative = omp_sync_hint_nonspeculative,
114         omp_sync_hint_speculative    = (1<<3),
115         omp_lock_hint_speculative    = omp_sync_hint_speculative,
116         kmp_lock_hint_hle            = (1<<16),
117         kmp_lock_hint_rtm            = (1<<17),
118         kmp_lock_hint_adaptive       = (1<<18)
119     } omp_sync_hint_t;
120 
121     /* lock hint type for dynamic user lock */
122     typedef omp_sync_hint_t omp_lock_hint_t;
123 
124     /* hinted lock initializers */
125     extern void __KAI_KMPC_CONVENTION omp_init_lock_with_hint(omp_lock_t *, omp_lock_hint_t);
126     extern void __KAI_KMPC_CONVENTION omp_init_nest_lock_with_hint(omp_nest_lock_t *, omp_lock_hint_t);
127 
128     /* time API functions */
129     extern double __KAI_KMPC_CONVENTION  omp_get_wtime (void);
130     extern double __KAI_KMPC_CONVENTION  omp_get_wtick (void);
131 
132     /* OpenMP 4.0 */
133     extern int  __KAI_KMPC_CONVENTION  omp_get_default_device (void);
134     extern void __KAI_KMPC_CONVENTION  omp_set_default_device (int);
135     extern int  __KAI_KMPC_CONVENTION  omp_is_initial_device (void);
136     extern int  __KAI_KMPC_CONVENTION  omp_get_num_devices (void);
137     extern int  __KAI_KMPC_CONVENTION  omp_get_num_teams (void);
138     extern int  __KAI_KMPC_CONVENTION  omp_get_team_num (void);
139     extern int  __KAI_KMPC_CONVENTION  omp_get_cancellation (void);
140 
141     /* OpenMP 4.5 */
142     extern int   __KAI_KMPC_CONVENTION  omp_get_initial_device (void);
143     extern void* __KAI_KMPC_CONVENTION  omp_target_alloc(size_t, int);
144     extern void  __KAI_KMPC_CONVENTION  omp_target_free(void *, int);
145     extern int   __KAI_KMPC_CONVENTION  omp_target_is_present(void *, int);
146     extern int   __KAI_KMPC_CONVENTION  omp_target_memcpy(void *, void *, size_t, size_t, size_t, int, int);
147     extern int   __KAI_KMPC_CONVENTION  omp_target_memcpy_rect(void *, void *, size_t, int, const size_t *,
148                                             const size_t *, const size_t *, const size_t *, const size_t *, int, int);
149     extern int   __KAI_KMPC_CONVENTION  omp_target_associate_ptr(void *, void *, size_t, size_t, int);
150     extern int   __KAI_KMPC_CONVENTION  omp_target_disassociate_ptr(void *, int);
151 
152     /* OpenMP 5.0 */
153     extern int   __KAI_KMPC_CONVENTION  omp_get_device_num (void);
154     typedef void * omp_depend_t;
155 
156     /* kmp API functions */
157     extern int    __KAI_KMPC_CONVENTION  kmp_get_stacksize          (void);
158     extern void   __KAI_KMPC_CONVENTION  kmp_set_stacksize          (int);
159     extern size_t __KAI_KMPC_CONVENTION  kmp_get_stacksize_s        (void);
160     extern void   __KAI_KMPC_CONVENTION  kmp_set_stacksize_s        (size_t);
161     extern int    __KAI_KMPC_CONVENTION  kmp_get_blocktime          (void);
162     extern int    __KAI_KMPC_CONVENTION  kmp_get_library            (void);
163     extern void   __KAI_KMPC_CONVENTION  kmp_set_blocktime          (int);
164     extern void   __KAI_KMPC_CONVENTION  kmp_set_library            (int);
165     extern void   __KAI_KMPC_CONVENTION  kmp_set_library_serial     (void);
166     extern void   __KAI_KMPC_CONVENTION  kmp_set_library_turnaround (void);
167     extern void   __KAI_KMPC_CONVENTION  kmp_set_library_throughput (void);
168     extern void   __KAI_KMPC_CONVENTION  kmp_set_defaults           (char const *);
169     extern void   __KAI_KMPC_CONVENTION  kmp_set_disp_num_buffers   (int);
170 
171     /* Intel affinity API */
172     typedef void * kmp_affinity_mask_t;
173 
174     extern int    __KAI_KMPC_CONVENTION  kmp_set_affinity             (kmp_affinity_mask_t *);
175     extern int    __KAI_KMPC_CONVENTION  kmp_get_affinity             (kmp_affinity_mask_t *);
176     extern int    __KAI_KMPC_CONVENTION  kmp_get_affinity_max_proc    (void);
177     extern void   __KAI_KMPC_CONVENTION  kmp_create_affinity_mask     (kmp_affinity_mask_t *);
178     extern void   __KAI_KMPC_CONVENTION  kmp_destroy_affinity_mask    (kmp_affinity_mask_t *);
179     extern int    __KAI_KMPC_CONVENTION  kmp_set_affinity_mask_proc   (int, kmp_affinity_mask_t *);
180     extern int    __KAI_KMPC_CONVENTION  kmp_unset_affinity_mask_proc (int, kmp_affinity_mask_t *);
181     extern int    __KAI_KMPC_CONVENTION  kmp_get_affinity_mask_proc   (int, kmp_affinity_mask_t *);
182 
183     /* OpenMP 4.0 affinity API */
184     typedef enum omp_proc_bind_t {
185         omp_proc_bind_false = 0,
186         omp_proc_bind_true = 1,
187         omp_proc_bind_master = 2,
188         omp_proc_bind_close = 3,
189         omp_proc_bind_spread = 4
190     } omp_proc_bind_t;
191 
192     extern omp_proc_bind_t __KAI_KMPC_CONVENTION omp_get_proc_bind (void);
193 
194     /* OpenMP 4.5 affinity API */
195     extern int  __KAI_KMPC_CONVENTION omp_get_num_places (void);
196     extern int  __KAI_KMPC_CONVENTION omp_get_place_num_procs (int);
197     extern void __KAI_KMPC_CONVENTION omp_get_place_proc_ids (int, int *);
198     extern int  __KAI_KMPC_CONVENTION omp_get_place_num (void);
199     extern int  __KAI_KMPC_CONVENTION omp_get_partition_num_places (void);
200     extern void __KAI_KMPC_CONVENTION omp_get_partition_place_nums (int *);
201 
202     extern void * __KAI_KMPC_CONVENTION  kmp_malloc  (size_t);
203     extern void * __KAI_KMPC_CONVENTION  kmp_aligned_malloc  (size_t, size_t);
204     extern void * __KAI_KMPC_CONVENTION  kmp_calloc  (size_t, size_t);
205     extern void * __KAI_KMPC_CONVENTION  kmp_realloc (void *, size_t);
206     extern void   __KAI_KMPC_CONVENTION  kmp_free    (void *);
207 
208     extern void   __KAI_KMPC_CONVENTION  kmp_set_warnings_on(void);
209     extern void   __KAI_KMPC_CONVENTION  kmp_set_warnings_off(void);
210 
211     /* OpenMP 5.0 Tool Control */
212     typedef enum omp_control_tool_result_t {
213         omp_control_tool_notool = -2,
214         omp_control_tool_nocallback = -1,
215         omp_control_tool_success = 0,
216         omp_control_tool_ignored = 1
217     } omp_control_tool_result_t;
218 
219     typedef enum omp_control_tool_t {
220         omp_control_tool_start = 1,
221         omp_control_tool_pause = 2,
222         omp_control_tool_flush = 3,
223         omp_control_tool_end = 4
224     } omp_control_tool_t;
225 
226     extern int __KAI_KMPC_CONVENTION omp_control_tool(int, int, void*);
227 
228     /* OpenMP 5.0 Memory Management */
229     typedef uintptr_t omp_uintptr_t;
230 
231     typedef enum {
232         OMP_ATK_THREADMODEL = 1,
233         OMP_ATK_ALIGNMENT = 2,
234         OMP_ATK_ACCESS = 3,
235         OMP_ATK_POOL_SIZE = 4,
236         OMP_ATK_FALLBACK = 5,
237         OMP_ATK_FB_DATA = 6,
238         OMP_ATK_PINNED = 7,
239         OMP_ATK_PARTITION = 8
240     } omp_alloctrait_key_t;
241 
242     typedef enum {
243         OMP_ATV_FALSE = 0,
244         OMP_ATV_TRUE = 1,
245         OMP_ATV_DEFAULT = 2,
246         OMP_ATV_CONTENDED = 3,
247         OMP_ATV_UNCONTENDED = 4,
248         OMP_ATV_SEQUENTIAL = 5,
249         OMP_ATV_PRIVATE = 6,
250         OMP_ATV_ALL = 7,
251         OMP_ATV_THREAD = 8,
252         OMP_ATV_PTEAM = 9,
253         OMP_ATV_CGROUP = 10,
254         OMP_ATV_DEFAULT_MEM_FB = 11,
255         OMP_ATV_NULL_FB = 12,
256         OMP_ATV_ABORT_FB = 13,
257         OMP_ATV_ALLOCATOR_FB = 14,
258         OMP_ATV_ENVIRONMENT = 15,
259         OMP_ATV_NEAREST = 16,
260         OMP_ATV_BLOCKED = 17,
261         OMP_ATV_INTERLEAVED = 18
262     } omp_alloctrait_value_t;
263 
264     typedef struct {
265         omp_alloctrait_key_t key;
266         omp_uintptr_t value;
267     } omp_alloctrait_t;
268 
269 #   if defined(_WIN32)
270     // On Windows cl and icl do not support 64-bit enum, let's use integer then.
271     typedef omp_uintptr_t omp_allocator_handle_t;
272     extern __KMP_IMP omp_allocator_handle_t const omp_null_allocator;
273     extern __KMP_IMP omp_allocator_handle_t const omp_default_mem_alloc;
274     extern __KMP_IMP omp_allocator_handle_t const omp_large_cap_mem_alloc;
275     extern __KMP_IMP omp_allocator_handle_t const omp_const_mem_alloc;
276     extern __KMP_IMP omp_allocator_handle_t const omp_high_bw_mem_alloc;
277     extern __KMP_IMP omp_allocator_handle_t const omp_low_lat_mem_alloc;
278     extern __KMP_IMP omp_allocator_handle_t const omp_cgroup_mem_alloc;
279     extern __KMP_IMP omp_allocator_handle_t const omp_pteam_mem_alloc;
280     extern __KMP_IMP omp_allocator_handle_t const omp_thread_mem_alloc;
281     typedef omp_uintptr_t omp_memspace_handle_t;
282     extern __KMP_IMP omp_memspace_handle_t const omp_default_mem_space;
283     extern __KMP_IMP omp_memspace_handle_t const omp_large_cap_mem_space;
284     extern __KMP_IMP omp_memspace_handle_t const omp_const_mem_space;
285     extern __KMP_IMP omp_memspace_handle_t const omp_high_bw_mem_space;
286     extern __KMP_IMP omp_memspace_handle_t const omp_low_lat_mem_space;
287 #   else
288 #       if __cplusplus >= 201103
289     typedef enum omp_allocator_handle_t : omp_uintptr_t
290 #       else
291     typedef enum omp_allocator_handle_t
292 #       endif
293     {
294       omp_null_allocator = 0,
295       omp_default_mem_alloc = 1,
296       omp_large_cap_mem_alloc = 2,
297       omp_const_mem_alloc = 3,
298       omp_high_bw_mem_alloc = 4,
299       omp_low_lat_mem_alloc = 5,
300       omp_cgroup_mem_alloc = 6,
301       omp_pteam_mem_alloc = 7,
302       omp_thread_mem_alloc = 8,
303       KMP_ALLOCATOR_MAX_HANDLE = UINTPTR_MAX
304     } omp_allocator_handle_t;
305 #       if __cplusplus >= 201103
306     typedef enum omp_memspace_handle_t : omp_uintptr_t
307 #       else
308     typedef enum omp_memspace_handle_t
309 #       endif
310     {
311       omp_default_mem_space = 0,
312       omp_large_cap_mem_space = 1,
313       omp_const_mem_space = 2,
314       omp_high_bw_mem_space = 3,
315       omp_low_lat_mem_space = 4,
316       KMP_MEMSPACE_MAX_HANDLE = UINTPTR_MAX
317     } omp_memspace_handle_t;
318 #   endif
319     extern omp_allocator_handle_t __KAI_KMPC_CONVENTION omp_init_allocator(omp_memspace_handle_t m,
320                                                        int ntraits, omp_alloctrait_t traits[]);
321     extern void __KAI_KMPC_CONVENTION omp_destroy_allocator(omp_allocator_handle_t allocator);
322 
323     extern void __KAI_KMPC_CONVENTION omp_set_default_allocator(omp_allocator_handle_t a);
324     extern omp_allocator_handle_t __KAI_KMPC_CONVENTION omp_get_default_allocator(void);
325 #   ifdef __cplusplus
326     extern void *__KAI_KMPC_CONVENTION omp_alloc(size_t size, omp_allocator_handle_t a = omp_null_allocator);
327     extern void __KAI_KMPC_CONVENTION omp_free(void * ptr, omp_allocator_handle_t a = omp_null_allocator);
328 #   else
329     extern void *__KAI_KMPC_CONVENTION omp_alloc(size_t size, omp_allocator_handle_t a);
330     extern void __KAI_KMPC_CONVENTION omp_free(void *ptr, omp_allocator_handle_t a);
331 #   endif
332 
333     /* OpenMP 5.0 Affinity Format */
334     extern void __KAI_KMPC_CONVENTION omp_set_affinity_format(char const *);
335     extern size_t __KAI_KMPC_CONVENTION omp_get_affinity_format(char *, size_t);
336     extern void __KAI_KMPC_CONVENTION omp_display_affinity(char const *);
337     extern size_t __KAI_KMPC_CONVENTION omp_capture_affinity(char *, size_t, char const *);
338 
339     /* OpenMP 5.0 events */
340 #   if defined(_WIN32)
341     // On Windows cl and icl do not support 64-bit enum, let's use integer then.
342     typedef omp_uintptr_t omp_event_handle_t;
343 #   else
344     typedef enum omp_event_handle_t { KMP_EVENT_MAX_HANDLE = UINTPTR_MAX } omp_event_handle_t;
345 #   endif
346     extern void __KAI_KMPC_CONVENTION omp_fulfill_event ( omp_event_handle_t event );
347 
348     /* OpenMP 5.0 Pause Resources */
349     typedef enum omp_pause_resource_t {
350       omp_pause_resume = 0,
351       omp_pause_soft = 1,
352       omp_pause_hard = 2
353     } omp_pause_resource_t;
354     extern int __KAI_KMPC_CONVENTION omp_pause_resource(omp_pause_resource_t, int);
355     extern int __KAI_KMPC_CONVENTION omp_pause_resource_all(omp_pause_resource_t);
356 
357     extern int __KAI_KMPC_CONVENTION omp_get_supported_active_levels(void);
358 
359 #   undef __KAI_KMPC_CONVENTION
360 #   undef __KMP_IMP
361 
362     /* Warning:
363        The following typedefs are not standard, deprecated and will be removed in a future release.
364     */
365     typedef int     omp_int_t;
366     typedef double  omp_wtime_t;
367 
368 #   ifdef __cplusplus
369     }
370 #   endif
371 
372 #endif /* __OMP_H */
373