Anastasia Stulova | b42f3c0 | 2017-04-21 15:13:24 +0000 | [diff] [blame] | 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="const volatile" |
| 3 | // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS= |
| 4 | // RUN: %clang_cc1 %s -cl-std=CL2.0 -triple "spir64-unknown-unknown" -verify -pedantic -fsyntax-only -Wconversion -DWCONV -DQUALS="const volatile" |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 5 | |
Anastasia Stulova | 58984e7 | 2017-02-16 12:27:47 +0000 | [diff] [blame] | 6 | typedef struct {int a;} ndrange_t; |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 7 | // Diagnostic tests for different overloads of enqueue_kernel from Table 6.13.17.1 of OpenCL 2.0 Spec. |
| 8 | kernel void enqueue_kernel_tests() { |
| 9 | queue_t default_queue; |
| 10 | unsigned flags = 0; |
Anastasia Stulova | b42f3c0 | 2017-04-21 15:13:24 +0000 | [diff] [blame] | 11 | QUALS ndrange_t ndrange; |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 12 | clk_event_t evt; |
| 13 | clk_event_t event_wait_list; |
| 14 | clk_event_t event_wait_list2[] = {evt, evt}; |
| 15 | void *vptr; |
| 16 | |
| 17 | // Testing the first overload type |
| 18 | enqueue_kernel(default_queue, flags, ndrange, ^(void) { |
| 19 | return 0; |
| 20 | }); |
| 21 | |
Joey Gouly | 6b03d95 | 2017-07-04 11:50:23 +0000 | [diff] [blame] | 22 | enqueue_kernel(vptr, flags, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'queue_t' argument type}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 23 | return 0; |
| 24 | }); |
| 25 | |
Joey Gouly | 6b03d95 | 2017-07-04 11:50:23 +0000 | [diff] [blame] | 26 | enqueue_kernel(default_queue, vptr, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'kernel_enqueue_flags_t' (i.e. uint) argument type}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 27 | return 0; |
| 28 | }); |
| 29 | |
Joey Gouly | 6b03d95 | 2017-07-04 11:50:23 +0000 | [diff] [blame] | 30 | enqueue_kernel(default_queue, flags, vptr, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'ndrange_t' argument type}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 31 | return 0; |
| 32 | }); |
| 33 | |
Joey Gouly | 6b03d95 | 2017-07-04 11:50:23 +0000 | [diff] [blame] | 34 | enqueue_kernel(default_queue, flags, ndrange, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 35 | |
Anastasia Stulova | 8ac3d0c | 2017-01-23 17:12:36 +0000 | [diff] [blame] | 36 | enqueue_kernel(default_queue, flags, ndrange, ^(int i) { // expected-error{{blocks with parameters are not accepted in this prototype of enqueue_kernel call}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 37 | return 0; |
| 38 | }); |
| 39 | |
| 40 | // Testing the second overload type |
| 41 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, ^(void) { |
Anastasia Stulova | 2b46120 | 2016-11-14 15:34:01 +0000 | [diff] [blame] | 42 | return 0; |
| 43 | }); |
| 44 | |
| 45 | enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0, ^(void) { |
| 46 | return 0; |
| 47 | }); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 48 | |
Joey Gouly | 6b03d95 | 2017-07-04 11:50:23 +0000 | [diff] [blame] | 49 | enqueue_kernel(default_queue, flags, ndrange, vptr, &event_wait_list, &evt, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected integer argument type}} |
Anastasia Stulova | 0df4ac3 | 2016-11-14 17:39:58 +0000 | [diff] [blame] | 50 | return 0; |
| 51 | }); |
| 52 | |
Joey Gouly | 6b03d95 | 2017-07-04 11:50:23 +0000 | [diff] [blame] | 53 | enqueue_kernel(default_queue, flags, ndrange, 1, vptr, &evt, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 54 | { |
| 55 | return 0; |
| 56 | }); |
| 57 | |
Joey Gouly | 6b03d95 | 2017-07-04 11:50:23 +0000 | [diff] [blame] | 58 | 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}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 59 | { |
| 60 | return 0; |
| 61 | }); |
| 62 | |
Joey Gouly | 6b03d95 | 2017-07-04 11:50:23 +0000 | [diff] [blame] | 63 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 64 | |
| 65 | // Testing the third overload type |
| 66 | enqueue_kernel(default_queue, flags, ndrange, |
| 67 | ^(local void *a, local void *b) { |
| 68 | return 0; |
| 69 | }, |
| 70 | 1024, 1024); |
| 71 | |
| 72 | enqueue_kernel(default_queue, flags, ndrange, |
| 73 | ^(local void *a, local void *b) { |
| 74 | return 0; |
| 75 | }, |
Anastasia Stulova | 0df4ac3 | 2016-11-14 17:39:58 +0000 | [diff] [blame] | 76 | 1024L, 1024); |
| 77 | |
| 78 | enqueue_kernel(default_queue, flags, ndrange, |
| 79 | ^(local void *a, local void *b) { |
| 80 | return 0; |
| 81 | }, |
| 82 | 1024, 4294967296L); |
| 83 | #ifdef B32 |
| 84 | // expected-warning@-2{{implicit conversion from 'long' to 'unsigned int' changes value from 4294967296 to 0}} |
| 85 | #endif |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 86 | |
| 87 | char c; |
| 88 | enqueue_kernel(default_queue, flags, ndrange, |
| 89 | ^(local void *a, local void *b) { |
| 90 | return 0; |
| 91 | }, |
Anastasia Stulova | 0df4ac3 | 2016-11-14 17:39:58 +0000 | [diff] [blame] | 92 | c, 1024L); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 93 | #ifdef WCONV |
Anastasia Stulova | 869d17d | 2019-12-27 13:38:48 +0000 | [diff] [blame] | 94 | // expected-warning-re@-2{{implicit conversion changes signedness: '__private char' to 'unsigned {{int|long}}'}} |
Anastasia Stulova | 0df4ac3 | 2016-11-14 17:39:58 +0000 | [diff] [blame] | 95 | #endif |
| 96 | #define UINT_MAX 4294967295 |
| 97 | |
| 98 | enqueue_kernel(default_queue, flags, ndrange, |
| 99 | ^(local void *a, local void *b) { |
| 100 | return 0; |
| 101 | }, |
| 102 | sizeof(int), sizeof(int) * UINT_MAX); |
| 103 | #ifdef B32 |
| 104 | // expected-warning@-2{{implicit conversion from 'long' to 'unsigned int' changes value from 17179869180 to 4294967292}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 105 | #endif |
| 106 | |
| 107 | typedef void (^bl_A_t)(local void *); |
| 108 | |
| 109 | const bl_A_t block_A = (bl_A_t) ^ (local void *a) {}; |
| 110 | |
| 111 | enqueue_kernel(default_queue, flags, ndrange, block_A, 1024); |
| 112 | |
| 113 | typedef void (^bl_B_t)(local void *, local int *); |
| 114 | |
| 115 | const bl_B_t block_B = (bl_B_t) ^ (local void *a, local int *b) {}; |
| 116 | |
Anastasia Stulova | 8ac3d0c | 2017-01-23 17:12:36 +0000 | [diff] [blame] | 117 | 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*'}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 118 | |
| 119 | enqueue_kernel(default_queue, flags, ndrange, // expected-error{{mismatch in number of block parameters and local size arguments passed}} |
| 120 | ^(local void *a, local void *b) { |
| 121 | return 0; |
| 122 | }, |
| 123 | 1024); |
| 124 | |
| 125 | float illegal_mem_size = (float)0.5f; |
| 126 | enqueue_kernel(default_queue, flags, ndrange, |
| 127 | ^(local void *a, local void *b) { |
| 128 | return 0; |
| 129 | }, |
Anastasia Stulova | 0df4ac3 | 2016-11-14 17:39:58 +0000 | [diff] [blame] | 130 | 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}} |
| 131 | |
| 132 | enqueue_kernel(default_queue, flags, ndrange, |
| 133 | ^(local void *a, local void *b) { |
| 134 | return 0; |
| 135 | }, |
| 136 | illegal_mem_size, 1024); // expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 137 | |
| 138 | // Testing the forth overload type |
| 139 | enqueue_kernel(default_queue, flags, ndrange, 1, event_wait_list2, &evt, |
| 140 | ^(local void *a, local void *b) { |
| 141 | return 0; |
| 142 | }, |
| 143 | 1024, 1024); |
| 144 | |
Anastasia Stulova | 2b46120 | 2016-11-14 15:34:01 +0000 | [diff] [blame] | 145 | enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0, |
| 146 | ^(local void *a, local void *b) { |
| 147 | return 0; |
| 148 | }, |
| 149 | 1024, 1024); |
| 150 | |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 151 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, // expected-error{{mismatch in number of block parameters and local size arguments passed}} |
| 152 | ^(local void *a, local void *b) { |
| 153 | return 0; |
| 154 | }, |
| 155 | 1024, 1024, 1024); |
| 156 | |
| 157 | // More random misc cases that can't be deduced |
| 158 | enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}} |
| 159 | |
| 160 | enqueue_kernel(default_queue, flags, ndrange, 1, 1); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}} |
Sven van Haastregt | a280b63 | 2019-08-29 10:21:06 +0000 | [diff] [blame] | 161 | |
| 162 | enqueue_kernel(default_queue, ndrange, ^{}); // expected-error{{too few arguments to function call, expected at least 4, have 3}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | // Diagnostic tests for get_kernel_work_group_size and allowed block parameter types in dynamic parallelism. |
| 166 | kernel void work_group_size_tests() { |
| 167 | void (^const block_A)(void) = ^{ |
| 168 | return; |
| 169 | }; |
| 170 | void (^const block_B)(int) = ^(int a) { |
| 171 | return; |
| 172 | }; |
| 173 | void (^const block_C)(local void *) = ^(local void *a) { |
| 174 | return; |
| 175 | }; |
| 176 | void (^const block_D)(local int *) = ^(local int *a) { |
| 177 | return; |
| 178 | }; |
| 179 | |
| 180 | unsigned size = get_kernel_work_group_size(block_A); |
| 181 | size = get_kernel_work_group_size(block_C); |
| 182 | size = get_kernel_work_group_size(^(local void *a) { |
| 183 | return; |
| 184 | }); |
Anastasia Stulova | 8ac3d0c | 2017-01-23 17:12:36 +0000 | [diff] [blame] | 185 | 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*'}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 186 | return; |
| 187 | }); |
Anastasia Stulova | 8ac3d0c | 2017-01-23 17:12:36 +0000 | [diff] [blame] | 188 | 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*'}} |
| 189 | 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*'}} |
| 190 | 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*'}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 191 | return; |
| 192 | }); |
| 193 | size = get_kernel_work_group_size(); // expected-error {{too few arguments to function call, expected 1, have 0}} |
| 194 | size = get_kernel_work_group_size(1); // expected-error{{expected block argument}} |
| 195 | size = get_kernel_work_group_size(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}} |
| 196 | |
| 197 | size = get_kernel_preferred_work_group_size_multiple(block_A); |
| 198 | size = get_kernel_preferred_work_group_size_multiple(block_C); |
| 199 | size = get_kernel_preferred_work_group_size_multiple(^(local void *a) { |
| 200 | return; |
| 201 | }); |
Anastasia Stulova | 8ac3d0c | 2017-01-23 17:12:36 +0000 | [diff] [blame] | 202 | 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*'}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 203 | return; |
| 204 | }); |
Anastasia Stulova | 8ac3d0c | 2017-01-23 17:12:36 +0000 | [diff] [blame] | 205 | 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*'}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 206 | return; |
| 207 | }); |
Anastasia Stulova | 8ac3d0c | 2017-01-23 17:12:36 +0000 | [diff] [blame] | 208 | 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*'}} |
| 209 | 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*'}} |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 210 | size = get_kernel_preferred_work_group_size_multiple(); // expected-error {{too few arguments to function call, expected 1, have 0}} |
| 211 | size = get_kernel_preferred_work_group_size_multiple(1); // expected-error{{expected block argument}} |
| 212 | size = get_kernel_preferred_work_group_size_multiple(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}} |
| 213 | } |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 214 | |
| 215 | #pragma OPENCL EXTENSION cl_khr_subgroups : enable |
| 216 | |
Marco Antognini | c0d541d | 2018-10-19 09:01:37 +0000 | [diff] [blame] | 217 | kernel void foo(global unsigned int *buf) |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 218 | { |
| 219 | ndrange_t n; |
| 220 | buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){}); |
| 221 | 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}} |
| 222 | 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}} |
| 223 | } |
| 224 | |
Marco Antognini | c0d541d | 2018-10-19 09:01:37 +0000 | [diff] [blame] | 225 | kernel void bar(global unsigned int *buf) |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 226 | { |
Yaxun Liu | b7318e0 | 2017-10-13 03:37:48 +0000 | [diff] [blame] | 227 | __private ndrange_t n; |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 228 | buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){}); |
| 229 | 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}} |
| 230 | 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}} |
| 231 | } |
| 232 | |
| 233 | #pragma OPENCL EXTENSION cl_khr_subgroups : disable |
| 234 | |
Marco Antognini | c0d541d | 2018-10-19 09:01:37 +0000 | [diff] [blame] | 235 | kernel void foo1(global unsigned int *buf) |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 236 | { |
| 237 | ndrange_t n; |
| 238 | 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 extension to be enabled}} |
| 239 | } |
| 240 | |
Marco Antognini | c0d541d | 2018-10-19 09:01:37 +0000 | [diff] [blame] | 241 | kernel void bar1(global unsigned int *buf) |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 242 | { |
| 243 | ndrange_t n; |
| 244 | 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 extension to be enabled}} |
| 245 | } |