1 | // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin10.6.0 -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc -o %t-host.bc %s |
2 | // RUN: %clang_cc1 -verify -DDEVICE -fopenmp -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -fsyntax-only %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc |
3 | // RUN: %clang_cc1 -verify -DDEVICE -DREQUIRES -fopenmp -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -fsyntax-only %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-host.bc |
4 | #if !defined(DEVICE) || defined(REQUIRES) |
5 | // expected-no-diagnostics |
6 | #endif // DEVICE |
7 | |
8 | #ifndef HEADER |
9 | #define HEADER |
10 | |
11 | #if defined(REQUIRES) && defined(DEVICE) |
12 | #pragma omp requires dynamic_allocators |
13 | #endif // REQUIRES && DEVICE |
14 | |
15 | int bar() { |
16 | int res = 0; |
17 | #if defined(DEVICE) && !defined(REQUIRES) |
18 | // expected-error@+2 {{expected an 'allocator' clause inside of the target region; provide an 'allocator' clause or use 'requires' directive with the 'dynamic_allocators' clause}} |
19 | #endif // DEVICE && !REQUIRES |
20 | #pragma omp allocate(res) |
21 | return 0; |
22 | } |
23 | |
24 | #pragma omp declare target |
25 | typedef void **omp_allocator_handle_t; |
26 | extern const omp_allocator_handle_t omp_default_mem_alloc; |
27 | extern const omp_allocator_handle_t omp_large_cap_mem_alloc; |
28 | extern const omp_allocator_handle_t omp_const_mem_alloc; |
29 | extern const omp_allocator_handle_t omp_high_bw_mem_alloc; |
30 | extern const omp_allocator_handle_t omp_low_lat_mem_alloc; |
31 | extern const omp_allocator_handle_t omp_cgroup_mem_alloc; |
32 | extern const omp_allocator_handle_t omp_pteam_mem_alloc; |
33 | extern const omp_allocator_handle_t omp_thread_mem_alloc; |
34 | |
35 | struct St{ |
36 | int a; |
37 | }; |
38 | |
39 | struct St1{ |
40 | int a; |
41 | static int b; |
42 | #pragma omp allocate(b) allocator(omp_default_mem_alloc) |
43 | } d; |
44 | |
45 | int a, b, c; |
46 | #pragma omp allocate(a) allocator(omp_large_cap_mem_alloc) |
47 | #pragma omp allocate(b) allocator(omp_const_mem_alloc) |
48 | #pragma omp allocate(d, c) allocator(omp_high_bw_mem_alloc) |
49 | |
50 | template <class T> |
51 | struct ST { |
52 | static T m; |
53 | #pragma omp allocate(m) allocator(omp_low_lat_mem_alloc) |
54 | }; |
55 | |
56 | template <class T> T foo() { |
57 | T v; |
58 | #pragma omp allocate(v) allocator(omp_cgroup_mem_alloc) |
59 | v = ST<T>::m; |
60 | return v; |
61 | } |
62 | |
63 | namespace ns{ |
64 | int a; |
65 | } |
66 | #pragma omp allocate(ns::a) allocator(omp_pteam_mem_alloc) |
67 | |
68 | int main () { |
69 | static int a; |
70 | #pragma omp allocate(a) allocator(omp_thread_mem_alloc) |
71 | a=2; |
72 | double b = 3; |
73 | #if defined(DEVICE) && !defined(REQUIRES) |
74 | // expected-error@+2 {{expected an 'allocator' clause inside of the target region; provide an 'allocator' clause or use 'requires' directive with the 'dynamic_allocators' clause}} |
75 | #endif // DEVICE && !REQUIRES |
76 | #pragma omp allocate(b) |
77 | #if defined(DEVICE) && !defined(REQUIRES) |
78 | // expected-note@+2 {{called by 'main'}} |
79 | #endif // DEVICE && !REQUIRES |
80 | return (foo<int>() + bar()); |
81 | } |
82 | |
83 | extern template int ST<int>::m; |
84 | #pragma omp end declare target |
85 | #endif |
86 | |