blob: e6fb83f63468ad7f205690c9bbb99f185bad7bf3 [file] [log] [blame]
Alexey Bataev2213dd62019-03-22 14:41:39 +00001// 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 Bataev318f431b2019-03-22 15:25:12 +00003// 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 Bataev2213dd62019-03-22 14:41:39 +00005// expected-no-diagnostics
6#endif // DEVICE
7
8#ifndef HEADER
9#define HEADER
10
Alexey Bataev318f431b2019-03-22 15:25:12 +000011#if defined(REQUIRES) && defined(DEVICE)
12#pragma omp requires dynamic_allocators
13#endif // REQUIRES && DEVICE
14
Alexey Bataev2213dd62019-03-22 14:41:39 +000015int bar() {
16 int res = 0;
Alexey Bataev318f431b2019-03-22 15:25:12 +000017#if defined(DEVICE) && !defined(REQUIRES)
Alexey Bataev2213dd62019-03-22 14:41:39 +000018// 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 Bataev318f431b2019-03-22 15:25:12 +000019#endif // DEVICE && !REQUIRES
Alexey Bataev2213dd62019-03-22 14:41:39 +000020#pragma omp allocate(res)
21 return 0;
22}
23
24#pragma omp declare target
25typedef void **omp_allocator_handle_t;
26extern const omp_allocator_handle_t omp_default_mem_alloc;
27extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
28extern const omp_allocator_handle_t omp_const_mem_alloc;
29extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
30extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
31extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
32extern const omp_allocator_handle_t omp_pteam_mem_alloc;
33extern const omp_allocator_handle_t omp_thread_mem_alloc;
34
35struct St{
36 int a;
37};
38
39struct St1{
40 int a;
41 static int b;
42#pragma omp allocate(b) allocator(omp_default_mem_alloc)
43} d;
44
45int 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
50template <class T>
51struct ST {
52 static T m;
53 #pragma omp allocate(m) allocator(omp_low_lat_mem_alloc)
54};
55
56template <class T> T foo() {
57 T v;
58 #pragma omp allocate(v) allocator(omp_cgroup_mem_alloc)
59 v = ST<T>::m;
Alexey Bataev84c8bae2019-04-01 16:56:59 +000060#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 Bataev2213dd62019-03-22 14:41:39 +000065 return v;
66}
67
68namespace ns{
69 int a;
70}
71#pragma omp allocate(ns::a) allocator(omp_pteam_mem_alloc)
72
73int main () {
74 static int a;
75#pragma omp allocate(a) allocator(omp_thread_mem_alloc)
76 a=2;
77 double b = 3;
Alexey Bataev318f431b2019-03-22 15:25:12 +000078#if defined(DEVICE) && !defined(REQUIRES)
Alexey Bataev2213dd62019-03-22 14:41:39 +000079// 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 Bataev318f431b2019-03-22 15:25:12 +000080#endif // DEVICE && !REQUIRES
Alexey Bataev2213dd62019-03-22 14:41:39 +000081#pragma omp allocate(b)
Alexey Bataev318f431b2019-03-22 15:25:12 +000082#if defined(DEVICE) && !defined(REQUIRES)
Alexey Bataev84c8bae2019-04-01 16:56:59 +000083// expected-note@+3 {{in instantiation of function template specialization 'foo<int>' requested here}}
Alexey Bataev2213dd62019-03-22 14:41:39 +000084// expected-note@+2 {{called by 'main'}}
Alexey Bataev318f431b2019-03-22 15:25:12 +000085#endif // DEVICE && !REQUIRES
Alexey Bataev2213dd62019-03-22 14:41:39 +000086 return (foo<int>() + bar());
87}
88
89extern template int ST<int>::m;
90#pragma omp end declare target
91#endif