fdeclare-opencl-builtins.cl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
  2. // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
  3. // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
  4. // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
  5. // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
  6. // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
  7. #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
  8. // expected-no-diagnostics
  9. #endif
  10. // Test the -fdeclare-opencl-builtins option.
  11. #pragma OPENCL EXTENSION cl_khr_fp16 : enable
  12. #if __OPENCL_C_VERSION__ < CL_VERSION_1_2
  13. #pragma OPENCL EXTENSION cl_khr_fp64 : enable
  14. #endif
  15. // Provide typedefs when invoking clang without -finclude-default-header.
  16. #ifdef NO_HEADER
  17. typedef char char2 __attribute__((ext_vector_type(2)));
  18. typedef char char4 __attribute__((ext_vector_type(4)));
  19. typedef float float4 __attribute__((ext_vector_type(4)));
  20. typedef half half4 __attribute__((ext_vector_type(4)));
  21. typedef int int2 __attribute__((ext_vector_type(2)));
  22. typedef int int4 __attribute__((ext_vector_type(4)));
  23. typedef long long2 __attribute__((ext_vector_type(2)));
  24. typedef unsigned char uchar;
  25. typedef unsigned int uint;
  26. typedef unsigned long ulong;
  27. typedef unsigned short ushort;
  28. typedef __SIZE_TYPE__ size_t;
  29. #endif
  30. kernel void test_pointers(volatile global void *global_p, global const int4 *a) {
  31. int i;
  32. unsigned int ui;
  33. prefetch(a, 2);
  34. atom_add((volatile __global int *)global_p, i);
  35. atom_cmpxchg((volatile __global unsigned int *)global_p, ui, ui);
  36. }
  37. kernel void basic_conversion() {
  38. double d;
  39. float f;
  40. char2 c2;
  41. long2 l2;
  42. float4 f4;
  43. int4 i4;
  44. f = convert_float(d);
  45. d = convert_double_sat_rtp(f);
  46. l2 = convert_long2_rtz(c2);
  47. i4 = convert_int4_sat(f4);
  48. }
  49. char4 test_int(char c, char4 c4) {
  50. char m = max(c, c);
  51. char4 m4 = max(c4, c4);
  52. return max(c4, c);
  53. }
  54. kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) {
  55. int2 i2;
  56. sampler_t sampler;
  57. half4 res;
  58. float4 resf;
  59. resf = read_imagef(image_read_only_image2d, i2);
  60. res = read_imageh(image_read_only_image2d, i2);
  61. res = read_imageh(image_read_only_image2d, sampler, i2);
  62. int imgWidth = get_image_width(image_read_only_image2d);
  63. }
  64. #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
  65. kernel void basic_image_readwrite(read_write image3d_t image_read_write_image3d) {
  66. half4 h4;
  67. int4 i4;
  68. write_imageh(image_read_write_image3d, i4, h4);
  69. int imgDepth = get_image_depth(image_read_write_image3d);
  70. }
  71. #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0
  72. kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_image1d_buffer) {
  73. half4 h4;
  74. float4 f4;
  75. int i;
  76. write_imagef(image_write_only_image1d_buffer, i, f4);
  77. write_imageh(image_write_only_image1d_buffer, i, h4);
  78. }
  79. kernel void basic_subgroup(global uint *out) {
  80. out[0] = get_sub_group_size();
  81. #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
  82. // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
  83. // expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}}
  84. #endif
  85. }
  86. kernel void basic_vector_data() {
  87. #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
  88. generic void *generic_p;
  89. #endif
  90. constant void *constant_p;
  91. local void *local_p;
  92. global void *global_p;
  93. private void *private_p;
  94. size_t s;
  95. vload4(s, (const __constant ulong *) constant_p);
  96. vload16(s, (const __constant short *) constant_p);
  97. #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
  98. vload3(s, (const __generic ushort *) generic_p);
  99. vload16(s, (const __generic uchar *) generic_p);
  100. #endif
  101. vload8(s, (const __global long *) global_p);
  102. vload2(s, (const __local uint *) local_p);
  103. vload16(s, (const __private float *) private_p);
  104. }
  105. kernel void basic_work_item() {
  106. uint ui;
  107. get_enqueued_local_size(ui);
  108. #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
  109. // expected-error@-2{{implicit declaration of function 'get_enqueued_local_size' is invalid in OpenCL}}
  110. #endif
  111. }