xref: /llvm-project/clang/test/SemaOpenCL/cl20-device-side-enqueue.cl (revision 4be105c98a9c7e083cd878ee1751e11160b97b4a)
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"
11
12typedef 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.
14kernel 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;
22
23  // Testing the first overload type
24  enqueue_kernel(default_queue, flags, ndrange, ^(void) {
25    return 0;
26  });
27
28  enqueue_kernel(vptr, flags, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'queue_t' argument type}}
29    return 0;
30  });
31
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  });
35
36  enqueue_kernel(default_queue, flags, vptr, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'ndrange_t' argument type}}
37    return 0;
38  });
39
40  enqueue_kernel(default_queue, flags, ndrange, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}}
41
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  });
45
46  // Testing the second overload type
47  enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, ^(void) {
48                                                                             return 0;
49                                                                           });
50
51  enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0, ^(void) {
52                                                           return 0;
53                                                         });
54
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  });
58
59  enqueue_kernel(default_queue, flags, ndrange, 1, vptr, &evt, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}}
60                                                               {
61                                                                 return 0;
62                                                               });
63
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}}
65                                                                           {
66                                                                             return 0;
67                                                                           });
68
69  enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}}
70
71  // Testing the third overload type
72  enqueue_kernel(default_queue, flags, ndrange,
73                 ^(local void *a, local void *b) {
74                   return 0;
75                 },
76                 1024, 1024);
77
78  enqueue_kernel(default_queue, flags, ndrange,
79                 ^(local void *a, local void *b) {
80                   return 0;
81                 },
82                 1024L, 1024);
83
84  enqueue_kernel(default_queue, flags, ndrange,
85                 ^(local void *a, local void *b) {
86                   return 0;
87                 },
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
92
93  char c;
94  enqueue_kernel(default_queue, flags, ndrange,
95                 ^(local void *a, local void *b) {
96                   return 0;
97                 },
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
103
104  enqueue_kernel(default_queue, flags, ndrange,
105                 ^(local void *a, local void *b) {
106                   return 0;
107                 },
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
112
113  typedef void (^bl_A_t)(local void *);
114
115  const bl_A_t block_A = (bl_A_t) ^ (local void *a) {};
116
117  enqueue_kernel(default_queue, flags, ndrange, block_A, 1024);
118
119  typedef void (^bl_B_t)(local void *, local int *);
120
121  const bl_B_t block_B = (bl_B_t) ^ (local void *a, local int *b) {};
122
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*'}}
124
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;
128                 },
129                 1024);
130
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;
135                 },
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}}
137
138  enqueue_kernel(default_queue, flags, ndrange,
139                 ^(local void *a, local void *b) {
140                   return 0;
141                 },
142                 illegal_mem_size, 1024); // expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}}
143
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;
148                 },
149                 1024, 1024);
150
151  enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0,
152                 ^(local void *a, local void *b) {
153                   return 0;
154                 },
155                 1024, 1024);
156
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;
160                 },
161                 1024, 1024, 1024);
162
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}}
165
166  enqueue_kernel(default_queue, flags, ndrange, 1, 1); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
167
168  enqueue_kernel(default_queue, ndrange, ^{}); // expected-error{{too few arguments to function call, expected at least 4, have 3}}
169}
170
171// Diagnostic tests for get_kernel_work_group_size and allowed block parameter types in dynamic parallelism.
172kernel void work_group_size_tests(void) {
173  void (^const block_A)(void) = ^{
174    return;
175  };
176  void (^const block_B)(int) = ^(int a) {
177    return;
178  };
179  void (^const block_C)(local void *) = ^(local void *a) {
180    return;
181  };
182  void (^const block_D)(local int *) = ^(local int *a) {
183    return;
184  };
185
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;
190  });
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;
193  });
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;
198  });
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}}
202
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;
207  });
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;
210  });
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;
213  });
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}}
219}
220
221#ifdef cl_khr_subgroups
222#pragma OPENCL EXTENSION cl_khr_subgroups : enable
223kernel void foo(global unsigned int *buf)
224{
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}}
229}
230
231kernel void bar(global unsigned int *buf)
232{
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}}
237}
238
239#pragma OPENCL EXTENSION cl_khr_subgroups : disable
240#else
241kernel void foo1(global unsigned int *buf)
242{
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}}
245}
246
247kernel void bar1(global unsigned int *buf)
248{
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}}
251}
252#endif // ifdef cl_khr_subgroups
253