1 //===--------- allocator.h - OpenMP target memory allocator ------- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Macros for allocating variables in different address spaces.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef OMPTARGET_ALLOCATOR_H
14 #define OMPTARGET_ALLOCATOR_H
15 
16 #if _OPENMP
17 // Follows the pattern in interface.h
18 // Clang sema checks this type carefully, needs to closely match that from omp.h
19 typedef enum omp_allocator_handle_t {
20   omp_null_allocator = 0,
21   omp_default_mem_alloc = 1,
22   omp_large_cap_mem_alloc = 2,
23   omp_const_mem_alloc = 3,
24   omp_high_bw_mem_alloc = 4,
25   omp_low_lat_mem_alloc = 5,
26   omp_cgroup_mem_alloc = 6,
27   omp_pteam_mem_alloc = 7,
28   omp_thread_mem_alloc = 8,
29   KMP_ALLOCATOR_MAX_HANDLE = ~(0U)
30 } omp_allocator_handle_t;
31 
32 #define __PRAGMA(STR) _Pragma(#STR)
33 #define OMP_PRAGMA(STR) __PRAGMA(omp STR)
34 
35 #define SHARED(NAME)                                                           \
36   NAME [[clang::loader_uninitialized]];                                        \
37   OMP_PRAGMA(allocate(NAME) allocator(omp_pteam_mem_alloc))
38 
39 #define EXTERN_SHARED(NAME)                                                    \
40   NAME;                                                                        \
41   OMP_PRAGMA(allocate(NAME) allocator(omp_pteam_mem_alloc))
42 #endif
43 
44 #endif // OMPTARGET_ALLOCATOR_H
45