Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaOpenCL / cl20-device-side-enqueue.cl
blob36b901fc5f29eda5cc9362a26f892e1913942abe
1 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS=
2 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups
3 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
4 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
5 // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
6 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS=
7 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS= -cl-ext=-cl_khr_subgroups,-__opencl_c_subgroups
8 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir-unknown-unknown" -verify -pedantic -fsyntax-only -DB32 -DQUALS="const volatile"
9 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS=
10 // RUN: %clang_cc1 %s -cl-std=CL3.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile"
12 typedef struct {int a;} ndrange_t;
13 // Diagnostic tests for different overloads of enqueue_kernel from Table 6.13.17.1 of OpenCL 2.0 Spec.
14 kernel void enqueue_kernel_tests(void) {
15 queue_t default_queue;
16 unsigned flags = 0;
17 QUALS ndrange_t ndrange;
18 clk_event_t evt;
19 clk_event_t event_wait_list;
20 clk_event_t event_wait_list2[] = {evt, evt};
21 void *vptr;
23 // Testing the first overload type
24 enqueue_kernel(default_queue, flags, ndrange, ^(void) {
25 return 0;
26 });
28 enqueue_kernel(vptr, flags, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'queue_t' argument type}}
29 return 0;
30 });
32 enqueue_kernel(default_queue, vptr, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'kernel_enqueue_flags_t' (i.e. uint) argument type}}
33 return 0;
34 });
36 enqueue_kernel(default_queue, flags, vptr, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'ndrange_t' argument type}}
37 return 0;
38 });
40 enqueue_kernel(default_queue, flags, ndrange, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}}
42 enqueue_kernel(default_queue, flags, ndrange, ^(int i) { // expected-error{{blocks with parameters are not accepted in this prototype of enqueue_kernel call}}
43 return 0;
44 });
46 // Testing the second overload type
47 enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, ^(void) {
48 return 0;
49 });
51 enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0, ^(void) {
52 return 0;
53 });
55 enqueue_kernel(default_queue, flags, ndrange, vptr, &event_wait_list, &evt, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected integer argument type}}
56 return 0;
57 });
59 enqueue_kernel(default_queue, flags, ndrange, 1, vptr, &evt, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}}
61 return 0;
62 });
64 enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, vptr, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}}
66 return 0;
67 });
69 enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}}
71 // Testing the third overload type
72 enqueue_kernel(default_queue, flags, ndrange,
73 ^(local void *a, local void *b) {
74 return 0;
76 1024, 1024);
78 enqueue_kernel(default_queue, flags, ndrange,
79 ^(local void *a, local void *b) {
80 return 0;
82 1024L, 1024);
84 enqueue_kernel(default_queue, flags, ndrange,
85 ^(local void *a, local void *b) {
86 return 0;
88 1024, 4294967296L);
89 #ifdef B32
90 // expected-warning@-2{{implicit conversion from 'long' to 'unsigned int' changes value from 4294967296 to 0}}
91 #endif
93 char c;
94 enqueue_kernel(default_queue, flags, ndrange,
95 ^(local void *a, local void *b) {
96 return 0;
98 c, 1024L);
99 #ifdef WCONV
100 // expected-warning-re@-2{{implicit conversion changes signedness: '__private char' to 'unsigned {{int|long}}'}}
101 #endif
102 #define UINT_MAX 4294967295
104 enqueue_kernel(default_queue, flags, ndrange,
105 ^(local void *a, local void *b) {
106 return 0;
108 sizeof(int), sizeof(int) * UINT_MAX);
109 #ifdef B32
110 // expected-warning@-2{{implicit conversion from 'long' to 'unsigned int' changes value from 17179869180 to 4294967292}}
111 #endif
113 typedef void (^bl_A_t)(local void *);
115 const bl_A_t block_A = (bl_A_t) ^ (local void *a) {};
117 enqueue_kernel(default_queue, flags, ndrange, block_A, 1024);
119 typedef void (^bl_B_t)(local void *, local int *);
121 const bl_B_t block_B = (bl_B_t) ^ (local void *a, local int *b) {};
123 enqueue_kernel(default_queue, flags, ndrange, block_B, 1024, 1024); // expected-error{{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
125 enqueue_kernel(default_queue, flags, ndrange, // expected-error{{mismatch in number of block parameters and local size arguments passed}}
126 ^(local void *a, local void *b) {
127 return 0;
129 1024);
131 float illegal_mem_size = (float)0.5f;
132 enqueue_kernel(default_queue, flags, ndrange,
133 ^(local void *a, local void *b) {
134 return 0;
136 illegal_mem_size, illegal_mem_size); // expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}} expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}}
138 enqueue_kernel(default_queue, flags, ndrange,
139 ^(local void *a, local void *b) {
140 return 0;
142 illegal_mem_size, 1024); // expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}}
144 // Testing the forth overload type
145 enqueue_kernel(default_queue, flags, ndrange, 1, event_wait_list2, &evt,
146 ^(local void *a, local void *b) {
147 return 0;
149 1024, 1024);
151 enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0,
152 ^(local void *a, local void *b) {
153 return 0;
155 1024, 1024);
157 enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, // expected-error{{mismatch in number of block parameters and local size arguments passed}}
158 ^(local void *a, local void *b) {
159 return 0;
161 1024, 1024, 1024);
163 // More random misc cases that can't be deduced
164 enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
166 enqueue_kernel(default_queue, flags, ndrange, 1, 1); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
168 enqueue_kernel(default_queue, ndrange, ^{}); // expected-error{{too few arguments to function call, expected at least 4, have 3}}
171 // Diagnostic tests for get_kernel_work_group_size and allowed block parameter types in dynamic parallelism.
172 kernel void work_group_size_tests(void) {
173 void (^const block_A)(void) = ^{
174 return;
176 void (^const block_B)(int) = ^(int a) {
177 return;
179 void (^const block_C)(local void *) = ^(local void *a) {
180 return;
182 void (^const block_D)(local int *) = ^(local int *a) {
183 return;
186 unsigned size = get_kernel_work_group_size(block_A);
187 size = get_kernel_work_group_size(block_C);
188 size = get_kernel_work_group_size(^(local void *a) {
189 return;
191 size = get_kernel_work_group_size(^(local int *a) { // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
192 return;
194 size = get_kernel_work_group_size(block_B); // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
195 size = get_kernel_work_group_size(block_D); // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
196 size = get_kernel_work_group_size(^(int a) { // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
197 return;
199 size = get_kernel_work_group_size(); // expected-error {{too few arguments to function call, expected 1, have 0}}
200 size = get_kernel_work_group_size(1); // expected-error{{expected block argument}}
201 size = get_kernel_work_group_size(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}}
203 size = get_kernel_preferred_work_group_size_multiple(block_A);
204 size = get_kernel_preferred_work_group_size_multiple(block_C);
205 size = get_kernel_preferred_work_group_size_multiple(^(local void *a) {
206 return;
208 size = get_kernel_preferred_work_group_size_multiple(^(local int *a) { // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
209 return;
211 size = get_kernel_preferred_work_group_size_multiple(^(int a) { // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
212 return;
214 size = get_kernel_preferred_work_group_size_multiple(block_B); // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
215 size = get_kernel_preferred_work_group_size_multiple(block_D); // expected-error {{blocks used in enqueue_kernel call are expected to have parameters of type 'local void*'}}
216 size = get_kernel_preferred_work_group_size_multiple(); // expected-error {{too few arguments to function call, expected 1, have 0}}
217 size = get_kernel_preferred_work_group_size_multiple(1); // expected-error{{expected block argument}}
218 size = get_kernel_preferred_work_group_size_multiple(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}}
221 #ifdef cl_khr_subgroups
222 #pragma OPENCL EXTENSION cl_khr_subgroups : enable
223 kernel void foo(global unsigned int *buf)
225 ndrange_t n;
226 buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){});
227 buf[0] = get_kernel_max_sub_group_size_for_ndrange(0, ^(){}); // expected-error{{illegal call to 'get_kernel_max_sub_group_size_for_ndrange', expected 'ndrange_t' argument type}}
228 buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, 1); // expected-error{{illegal call to 'get_kernel_max_sub_group_size_for_ndrange', expected block argument type}}
231 kernel void bar(global unsigned int *buf)
233 __private ndrange_t n;
234 buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){});
235 buf[0] = get_kernel_sub_group_count_for_ndrange(0, ^(){}); // expected-error{{illegal call to 'get_kernel_sub_group_count_for_ndrange', expected 'ndrange_t' argument type}}
236 buf[0] = get_kernel_sub_group_count_for_ndrange(n, 1); // expected-error{{illegal call to 'get_kernel_sub_group_count_for_ndrange', expected block argument type}}
239 #pragma OPENCL EXTENSION cl_khr_subgroups : disable
240 #else
241 kernel void foo1(global unsigned int *buf)
243 ndrange_t n;
244 buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_max_sub_group_size_for_ndrange' requires cl_khr_subgroups or __opencl_c_subgroups support}}
247 kernel void bar1(global unsigned int *buf)
249 ndrange_t n;
250 buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); // expected-error {{use of declaration 'get_kernel_sub_group_count_for_ndrange' requires cl_khr_subgroups or __opencl_c_subgroups support}}
252 #endif // ifdef cl_khr_subgroups