cl20-device-side-enqueue.cl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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"
  5. typedef struct {int a;} ndrange_t;
  6. // Diagnostic tests for different overloads of enqueue_kernel from Table 6.13.17.1 of OpenCL 2.0 Spec.
  7. kernel void enqueue_kernel_tests() {
  8. queue_t default_queue;
  9. unsigned flags = 0;
  10. QUALS ndrange_t ndrange;
  11. clk_event_t evt;
  12. clk_event_t event_wait_list;
  13. clk_event_t event_wait_list2[] = {evt, evt};
  14. void *vptr;
  15. // Testing the first overload type
  16. enqueue_kernel(default_queue, flags, ndrange, ^(void) {
  17. return 0;
  18. });
  19. enqueue_kernel(vptr, flags, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'queue_t' argument type}}
  20. return 0;
  21. });
  22. enqueue_kernel(default_queue, vptr, ndrange, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'kernel_enqueue_flags_t' (i.e. uint) argument type}}
  23. return 0;
  24. });
  25. enqueue_kernel(default_queue, flags, vptr, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected 'ndrange_t' argument type}}
  26. return 0;
  27. });
  28. enqueue_kernel(default_queue, flags, ndrange, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}}
  29. enqueue_kernel(default_queue, flags, ndrange, ^(int i) { // expected-error{{blocks with parameters are not accepted in this prototype of enqueue_kernel call}}
  30. return 0;
  31. });
  32. // Testing the second overload type
  33. enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, ^(void) {
  34. return 0;
  35. });
  36. enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0, ^(void) {
  37. return 0;
  38. });
  39. enqueue_kernel(default_queue, flags, ndrange, vptr, &event_wait_list, &evt, ^(void) { // expected-error{{illegal call to 'enqueue_kernel', expected integer argument type}}
  40. return 0;
  41. });
  42. enqueue_kernel(default_queue, flags, ndrange, 1, vptr, &evt, ^(void) // expected-error{{illegal call to 'enqueue_kernel', expected 'clk_event_t *' argument type}}
  43. {
  44. return 0;
  45. });
  46. 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}}
  47. {
  48. return 0;
  49. });
  50. enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, vptr); // expected-error{{illegal call to 'enqueue_kernel', expected block argument}}
  51. // Testing the third overload type
  52. enqueue_kernel(default_queue, flags, ndrange,
  53. ^(local void *a, local void *b) {
  54. return 0;
  55. },
  56. 1024, 1024);
  57. enqueue_kernel(default_queue, flags, ndrange,
  58. ^(local void *a, local void *b) {
  59. return 0;
  60. },
  61. 1024L, 1024);
  62. enqueue_kernel(default_queue, flags, ndrange,
  63. ^(local void *a, local void *b) {
  64. return 0;
  65. },
  66. 1024, 4294967296L);
  67. #ifdef B32
  68. // expected-warning@-2{{implicit conversion from 'long' to 'unsigned int' changes value from 4294967296 to 0}}
  69. #endif
  70. char c;
  71. enqueue_kernel(default_queue, flags, ndrange,
  72. ^(local void *a, local void *b) {
  73. return 0;
  74. },
  75. c, 1024L);
  76. #ifdef WCONV
  77. // expected-warning-re@-2{{implicit conversion changes signedness: 'char' to 'unsigned {{int|long}}'}}
  78. #endif
  79. #define UINT_MAX 4294967295
  80. enqueue_kernel(default_queue, flags, ndrange,
  81. ^(local void *a, local void *b) {
  82. return 0;
  83. },
  84. sizeof(int), sizeof(int) * UINT_MAX);
  85. #ifdef B32
  86. // expected-warning@-2{{implicit conversion from 'long' to 'unsigned int' changes value from 17179869180 to 4294967292}}
  87. #endif
  88. typedef void (^bl_A_t)(local void *);
  89. const bl_A_t block_A = (bl_A_t) ^ (local void *a) {};
  90. enqueue_kernel(default_queue, flags, ndrange, block_A, 1024);
  91. typedef void (^bl_B_t)(local void *, local int *);
  92. const bl_B_t block_B = (bl_B_t) ^ (local void *a, local int *b) {};
  93. 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*'}}
  94. enqueue_kernel(default_queue, flags, ndrange, // expected-error{{mismatch in number of block parameters and local size arguments passed}}
  95. ^(local void *a, local void *b) {
  96. return 0;
  97. },
  98. 1024);
  99. float illegal_mem_size = (float)0.5f;
  100. enqueue_kernel(default_queue, flags, ndrange,
  101. ^(local void *a, local void *b) {
  102. return 0;
  103. },
  104. 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}}
  105. enqueue_kernel(default_queue, flags, ndrange,
  106. ^(local void *a, local void *b) {
  107. return 0;
  108. },
  109. illegal_mem_size, 1024); // expected-error{{illegal call to enqueue_kernel, parameter needs to be specified as integer type}}
  110. // Testing the forth overload type
  111. enqueue_kernel(default_queue, flags, ndrange, 1, event_wait_list2, &evt,
  112. ^(local void *a, local void *b) {
  113. return 0;
  114. },
  115. 1024, 1024);
  116. enqueue_kernel(default_queue, flags, ndrange, 1, 0, 0,
  117. ^(local void *a, local void *b) {
  118. return 0;
  119. },
  120. 1024, 1024);
  121. enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt, // expected-error{{mismatch in number of block parameters and local size arguments passed}}
  122. ^(local void *a, local void *b) {
  123. return 0;
  124. },
  125. 1024, 1024, 1024);
  126. // More random misc cases that can't be deduced
  127. enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
  128. enqueue_kernel(default_queue, flags, ndrange, 1, 1); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
  129. enqueue_kernel(default_queue, ndrange, ^{}); // expected-error{{too few arguments to function call, expected at least 4, have 3}}
  130. }
  131. // Diagnostic tests for get_kernel_work_group_size and allowed block parameter types in dynamic parallelism.
  132. kernel void work_group_size_tests() {
  133. void (^const block_A)(void) = ^{
  134. return;
  135. };
  136. void (^const block_B)(int) = ^(int a) {
  137. return;
  138. };
  139. void (^const block_C)(local void *) = ^(local void *a) {
  140. return;
  141. };
  142. void (^const block_D)(local int *) = ^(local int *a) {
  143. return;
  144. };
  145. unsigned size = get_kernel_work_group_size(block_A);
  146. size = get_kernel_work_group_size(block_C);
  147. size = get_kernel_work_group_size(^(local void *a) {
  148. return;
  149. });
  150. 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*'}}
  151. return;
  152. });
  153. 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*'}}
  154. 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*'}}
  155. 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*'}}
  156. return;
  157. });
  158. size = get_kernel_work_group_size(); // expected-error {{too few arguments to function call, expected 1, have 0}}
  159. size = get_kernel_work_group_size(1); // expected-error{{expected block argument}}
  160. size = get_kernel_work_group_size(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}}
  161. size = get_kernel_preferred_work_group_size_multiple(block_A);
  162. size = get_kernel_preferred_work_group_size_multiple(block_C);
  163. size = get_kernel_preferred_work_group_size_multiple(^(local void *a) {
  164. return;
  165. });
  166. 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*'}}
  167. return;
  168. });
  169. 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*'}}
  170. return;
  171. });
  172. 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*'}}
  173. 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*'}}
  174. size = get_kernel_preferred_work_group_size_multiple(); // expected-error {{too few arguments to function call, expected 1, have 0}}
  175. size = get_kernel_preferred_work_group_size_multiple(1); // expected-error{{expected block argument}}
  176. size = get_kernel_preferred_work_group_size_multiple(block_A, 1); // expected-error{{too many arguments to function call, expected 1, have 2}}
  177. }
  178. #pragma OPENCL EXTENSION cl_khr_subgroups : enable
  179. kernel void foo(global unsigned int *buf)
  180. {
  181. ndrange_t n;
  182. buf[0] = get_kernel_max_sub_group_size_for_ndrange(n, ^(){});
  183. 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}}
  184. 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}}
  185. }
  186. kernel void bar(global unsigned int *buf)
  187. {
  188. __private ndrange_t n;
  189. buf[0] = get_kernel_sub_group_count_for_ndrange(n, ^(){});
  190. 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}}
  191. 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}}
  192. }
  193. #pragma OPENCL EXTENSION cl_khr_subgroups : disable
  194. kernel void foo1(global unsigned int *buf)
  195. {
  196. ndrange_t n;
  197. 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}}
  198. }
  199. kernel void bar1(global unsigned int *buf)
  200. {
  201. ndrange_t n;
  202. 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}}
  203. }