Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 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 |
Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 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) |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 5 | // expected-no-diagnostics |
| 6 | #endif // DEVICE |
| 7 | |
| 8 | #ifndef HEADER |
| 9 | #define HEADER |
| 10 | |
Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 11 | #if defined(REQUIRES) && defined(DEVICE) |
| 12 | #pragma omp requires dynamic_allocators |
| 13 | #endif // REQUIRES && DEVICE |
| 14 | |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 15 | int bar() { |
| 16 | int res = 0; |
Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 17 | #if defined(DEVICE) && !defined(REQUIRES) |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 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}} |
Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 19 | #endif // DEVICE && !REQUIRES |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 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; |
Alexey Bataev | 84c8bae | 2019-04-01 16:56:59 +0000 | [diff] [blame] | 60 | #if defined(DEVICE) && !defined(REQUIRES) |
| 61 | // expected-error@+2 2 {{expected an allocator expression inside of the target region; provide an allocator expression or use 'requires' directive with the 'dynamic_allocators' clause}} |
| 62 | #endif // DEVICE && !REQUIRES |
| 63 | #pragma omp parallel private(v) allocate(v) |
| 64 | v = 0; |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 65 | return v; |
| 66 | } |
| 67 | |
| 68 | namespace ns{ |
| 69 | int a; |
| 70 | } |
| 71 | #pragma omp allocate(ns::a) allocator(omp_pteam_mem_alloc) |
| 72 | |
| 73 | int main () { |
| 74 | static int a; |
| 75 | #pragma omp allocate(a) allocator(omp_thread_mem_alloc) |
| 76 | a=2; |
| 77 | double b = 3; |
Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 78 | #if defined(DEVICE) && !defined(REQUIRES) |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 79 | // 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}} |
Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 80 | #endif // DEVICE && !REQUIRES |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 81 | #pragma omp allocate(b) |
Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 82 | #if defined(DEVICE) && !defined(REQUIRES) |
Alexey Bataev | 84c8bae | 2019-04-01 16:56:59 +0000 | [diff] [blame] | 83 | // expected-note@+3 {{in instantiation of function template specialization 'foo<int>' requested here}} |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 84 | // expected-note@+2 {{called by 'main'}} |
Alexey Bataev | 318f431b | 2019-03-22 15:25:12 +0000 | [diff] [blame] | 85 | #endif // DEVICE && !REQUIRES |
Alexey Bataev | 2213dd6 | 2019-03-22 14:41:39 +0000 | [diff] [blame] | 86 | return (foo<int>() + bar()); |
| 87 | } |
| 88 | |
| 89 | extern template int ST<int>::m; |
| 90 | #pragma omp end declare target |
| 91 | #endif |