File: opencl-c-header.cl

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (367 lines) | stat: -rw-r--r-- 15,742 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 | FileCheck %s
// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 | FileCheck %s
// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++1.0 | FileCheck %s --check-prefix=CHECK20
// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL3.0 | FileCheck %s
// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++2021 | FileCheck %s

// RUN: %clang_cc1 -O0 -triple spirv32-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s


// Test including the default header as a module.
// The module should be compiled only once and loaded from cache afterwards.
// Change the directory mode to read only to make sure no new modules are created.
// Check time report to make sure module is used.
// Check that some builtins occur in the generated IR when called.

// ===
// Clear current directory.
// RUN: rm -rf %t
// RUN: mkdir -p %t

// ===
// Compile for OpenCL 1.0 for the first time. A module should be generated.
// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -o - -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s
// RUN: chmod u-w %t/opencl_c.pcm

// ===
// Compile for OpenCL 1.0 for the second time. The module should not be re-created.
// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm -o - -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s
// RUN: chmod u+w %t/opencl_c.pcm
// RUN: mv %t/opencl_c.pcm %t/1_0.pcm

// ===
// Compile for OpenCL 2.0 for the first time. The module should change.
// RUN: %clang_cc1 -triple spir-unknown-unknown -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
// RUN: not diff %t/1_0.pcm %t/opencl_c.pcm
// RUN: chmod u-w %t/opencl_c.pcm

// ===
// Compile for OpenCL 2.0 for the second time. The module should not change.
// RUN: %clang_cc1 -triple spir-unknown-unknown -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fdisable-module-hash -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s

// Check cached module works for different OpenCL versions.
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm -o - -cl-std=CL1.2 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s
// RUN: %clang_cc1 -triple amdgcn--amdhsa -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
// RUN: chmod u-w %t 
// RUN: %clang_cc1 -triple spir64-unknown-unknown -emit-llvm -o - -cl-std=CL1.2 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-MOD %s
// RUN: %clang_cc1 -triple amdgcn--amdhsa -O0 -emit-llvm -o - -cl-std=CL2.0 -finclude-default-header -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -ftime-report %s 2>&1 | FileCheck --check-prefix=CHECK20 --check-prefix=CHECK-MOD %s
// RUN: chmod u+w %t

// Verify that called builtins occur in the generated IR.

// CHECK-NOT: intel_sub_group_avc_mce_get_default_inter_base_multi_reference_penalty
// CHECK-NOT: ndrange_t
// CHECK20: ndrange_t
// CHECK: _Z16convert_char_rtec
// CHECK-NOT: _Z3ctzc
// CHECK20: _Z3ctzc
// CHECK20: _Z16convert_char_rtec
char f(char x) {
// Check functionality from OpenCL 2.0 onwards
#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
  ndrange_t t;
  x = ctz(x);
#endif //__OPENCL_C_VERSION__
  return convert_char_rte(x);
}

// Verify that a builtin using a write_only image3d_t type is available
// from OpenCL 2.0 onwards.

// CHECK20: _Z12write_imagef14ocl_image3d_wo
#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
void test_image3dwo(write_only image3d_t img) {
  write_imagef(img, (0), (0.0f));
}
#endif //__OPENCL_C_VERSION__

#if defined(__OPENCL_CPP_VERSION__)
// Test old atomic overloaded with generic addr space.
void test_atomics(__generic volatile unsigned int* a) {
  atomic_add(a, 1);
}
#endif

// Verify that ATOMIC_VAR_INIT is defined.
#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
global atomic_int z = ATOMIC_VAR_INIT(99);
#endif //__OPENCL_C_VERSION__
// CHECK-MOD: Reading modules

// Check that extension macros are defined correctly.

// For SPIR all extensions are supported.
#if defined(__SPIR__) || defined(__SPIRV__)

// Verify that cl_intel_planar_yuv extension is defined from OpenCL 1.2 onwards.
#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
// expected-no-diagnostics
#else //__OPENCL_C_VERSION__
// expected-warning@+2{{OpenCL extension 'cl_intel_planar_yuv' unknown or does not require pragma - ignoring}}
#endif //__OPENCL_C_VERSION__
#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable

#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)

#if cl_khr_subgroup_extended_types != 1
#error "Incorrectly defined cl_khr_subgroup_extended_types"
#endif
#if cl_khr_subgroup_non_uniform_vote != 1
#error "Incorrectly defined cl_khr_subgroup_non_uniform_vote"
#endif
#if cl_khr_subgroup_ballot != 1
#error "Incorrectly defined cl_khr_subgroup_ballot"
#endif
#if cl_khr_subgroup_non_uniform_arithmetic != 1
#error "Incorrectly defined cl_khr_subgroup_non_uniform_arithmetic"
#endif
#if cl_khr_subgroup_shuffle != 1
#error "Incorrectly defined cl_khr_subgroup_shuffle"
#endif
#if cl_khr_subgroup_shuffle_relative != 1
#error "Incorrectly defined cl_khr_subgroup_shuffle_relative"
#endif
#if cl_khr_subgroup_clustered_reduce != 1
#error "Incorrectly defined cl_khr_subgroup_clustered_reduce"
#endif
#if cl_khr_subgroup_rotate != 1
#error "Incorrectly defined cl_khr_subgroup_rotate"
#endif
#if cl_khr_extended_bit_ops != 1
#error "Incorrectly defined cl_khr_extended_bit_ops"
#endif
#if cl_khr_integer_dot_product != 1
#error "Incorrectly defined cl_khr_integer_dot_product"
#endif
#if __opencl_c_integer_dot_product_input_4x8bit != 1
#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit"
#endif
#if __opencl_c_integer_dot_product_input_4x8bit_packed != 1
#error "Incorrectly defined __opencl_c_integer_dot_product_input_4x8bit_packed"
#endif
#if cl_ext_float_atomics != 1
#error "Incorrectly defined cl_ext_float_atomics"
#endif
#if __opencl_c_ext_fp16_global_atomic_load_store != 1
#error "Incorrectly defined __opencl_c_ext_fp16_global_atomic_load_store"
#endif
#if __opencl_c_ext_fp16_local_atomic_load_store != 1
#error "Incorrectly defined __opencl_c_ext_fp16_local_atomic_load_store"
#endif
#if __opencl_c_ext_fp16_global_atomic_add != 1
#error "Incorrectly defined __opencl_c_ext_fp16_global_atomic_add"
#endif
#if __opencl_c_ext_fp32_global_atomic_add != 1
#error "Incorrectly defined __opencl_c_ext_fp32_global_atomic_add"
#endif
#if __opencl_c_ext_fp64_global_atomic_add != 1
#error "Incorrectly defined __opencl_c_ext_fp64_global_atomic_add"
#endif
#if __opencl_c_ext_fp16_local_atomic_add != 1
#error "Incorrectly defined __opencl_c_ext_fp16_local_atomic_add"
#endif
#if __opencl_c_ext_fp32_local_atomic_add != 1
#error "Incorrectly defined __opencl_c_ext_fp32_local_atomic_add"
#endif
#if __opencl_c_ext_fp64_local_atomic_add != 1
#error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_add"
#endif
#if __opencl_c_ext_fp16_global_atomic_min_max != 1
#error "Incorrectly defined __opencl_c_ext_fp16_global_atomic_min_max"
#endif
#if __opencl_c_ext_fp32_global_atomic_min_max != 1
#error "Incorrectly defined __opencl_c_ext_fp32_global_atomic_min_max"
#endif
#if __opencl_c_ext_fp64_global_atomic_min_max != 1
#error "Incorrectly defined __opencl_c_ext_fp64_global_atomic_min_max"
#endif
#if __opencl_c_ext_fp16_local_atomic_min_max != 1
#error "Incorrectly defined __opencl_c_ext_fp16_local_atomic_min_max"
#endif
#if __opencl_c_ext_fp32_local_atomic_min_max != 1
#error "Incorrectly defined __opencl_c_ext_fp32_local_atomic_min_max"
#endif
#if __opencl_c_ext_fp64_local_atomic_min_max != 1
#error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
#endif

#else

#ifdef cl_khr_subgroup_extended_types
#error "Incorrect cl_khr_subgroup_extended_types define"
#endif
#ifdef cl_khr_subgroup_non_uniform_vote
#error "Incorrect cl_khr_subgroup_non_uniform_vote define"
#endif
#ifdef cl_khr_subgroup_ballot
#error "Incorrect cl_khr_subgroup_ballot define"
#endif
#ifdef cl_khr_subgroup_non_uniform_arithmetic
#error "Incorrect cl_khr_subgroup_non_uniform_arithmetic define"
#endif
#ifdef cl_khr_subgroup_shuffle
#error "Incorrect cl_khr_subgroup_shuffle define"
#endif
#ifdef cl_khr_subgroup_shuffle_relative
#error "Incorrect cl_khr_subgroup_shuffle_relative define"
#endif
#ifdef cl_khr_subgroup_clustered_reduce
#error "Incorrect cl_khr_subgroup_clustered_reduce define"
#endif
#ifdef cl_khr_subgroup_rotate
#error "Incorrect cl_khr_subgroup_rotate define"
#endif
#ifdef cl_khr_extended_bit_ops
#error "Incorrect cl_khr_extended_bit_ops define"
#endif
#ifdef cl_khr_integer_dot_product
#error "Incorrect cl_khr_integer_dot_product define"
#endif
#ifdef __opencl_c_integer_dot_product_input_4x8bit
#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit define"
#endif
#ifdef __opencl_c_integer_dot_product_input_4x8bit_packed
#error "Incorrect __opencl_c_integer_dot_product_input_4x8bit_packed define"
#endif
#ifdef cl_ext_float_atomics
#error "Incorrect cl_ext_float_atomics define"
#endif
#ifdef __opencl_c_ext_fp16_global_atomic_load_store
#error "Incorrectly __opencl_c_ext_fp16_global_atomic_load_store defined"
#endif
#ifdef __opencl_c_ext_fp16_local_atomic_load_store
#error "Incorrectly __opencl_c_ext_fp16_local_atomic_load_store defined"
#endif
#ifdef __opencl_c_ext_fp16_global_atomic_add
#error "Incorrectly __opencl_c_ext_fp16_global_atomic_add defined"
#endif
#ifdef __opencl_c_ext_fp32_global_atomic_add
#error "Incorrectly __opencl_c_ext_fp32_global_atomic_add defined"
#endif
#ifdef __opencl_c_ext_fp64_global_atomic_add
#error "Incorrectly __opencl_c_ext_fp64_global_atomic_add defined"
#endif
#ifdef __opencl_c_ext_fp16_local_atomic_add
#error "Incorrectly __opencl_c_ext_fp16_local_atomic_add defined"
#endif
#ifdef __opencl_c_ext_fp32_local_atomic_add
#error "Incorrectly __opencl_c_ext_fp32_local_atomic_add defined"
#endif
#ifdef __opencl_c_ext_fp64_local_atomic_add
#error "Incorrectly __opencl_c_ext_fp64_local_atomic_add defined"
#endif
#ifdef __opencl_c_ext_fp16_global_atomic_min_max
#error "Incorrectly __opencl_c_ext_fp16_global_atomic_min_max defined"
#endif
#ifdef __opencl_c_ext_fp32_global_atomic_min_max
#error "Incorrectly __opencl_c_ext_fp32_global_atomic_min_max defined"
#endif
#ifdef __opencl_c_ext_fp64_global_atomic_min_max
#error "Incorrectly __opencl_c_ext_fp64_global_atomic_min_max defined"
#endif
#ifdef __opencl_c_ext_fp16_local_atomic_min_max
#error "Incorrectly __opencl_c_ext_fp16_local_atomic_min_max defined"
#endif
#ifdef __opencl_c_ext_fp32_local_atomic_min_max
#error "Incorrectly __opencl_c_ext_fp32_local_atomic_min_max defined"
#endif
#ifdef __opencl_c_ext_fp64_local_atomic_min_max
#error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
#endif

#endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)

// OpenCL C features.
#if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)

#if __opencl_c_atomic_scope_all_devices != 1
#error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices"
#endif

#elif (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)

#ifndef  __opencl_c_pipes
#error "Feature macro __opencl_c_pipes should be defined"
#endif
#ifndef __opencl_c_generic_address_space
#error "Feature macro __opencl_c_generic_address_space should be defined"
#endif
#ifndef __opencl_c_work_group_collective_functions
#error "Feature macro __opencl_c_work_group_collective_functions should be defined"
#endif
#ifndef __opencl_c_atomic_order_acq_rel
#error "Feature macro __opencl_c_atomic_order_acq_rel should be defined"
#endif
#ifndef __opencl_c_atomic_order_seq_cst
#error "Feature macro __opencl_c_atomic_order_seq_cst should be defined"
#endif
#ifndef __opencl_c_atomic_scope_device
#error "Feature macro __opencl_c_atomic_scope_device should be defined"
#endif
#ifndef __opencl_c_atomic_scope_all_devices
#error "Feature macro __opencl_c_atomic_scope_all_devices should be defined"
#endif
#ifndef __opencl_c_device_enqueue
#error "Feature macro __opencl_c_device_enqueue should be defined"
#endif
#ifndef __opencl_c_read_write_images
#error "Feature macro __opencl_c_read_write_images should be defined"
#endif
#ifndef __opencl_c_program_scope_global_variables
#error "Feature macro __opencl_c_program_scope_global_variables should be defined"
#endif
#ifndef __opencl_c_images
#error "Feature macro __opencl_c_images should be defined"
#endif

#elif (__OPENCL_C_VERSION__ < 200)

#ifdef  __opencl_c_pipes
#error "Incorrect feature macro __opencl_c_pipes define"
#endif
#ifdef __opencl_c_generic_address_space
#error "Incorrect feature macro __opencl_c_generic_address_space define"
#endif
#ifdef __opencl_c_work_group_collective_functions
#error "Incorrect feature macro __opencl_c_work_group_collective_functions define"
#endif
#ifdef __opencl_c_atomic_order_acq_rel
#error "Incorrect feature macro __opencl_c_atomic_order_acq_rel define"
#endif
#ifdef __opencl_c_atomic_order_seq_cst
#error "Incorrect feature macro __opencl_c_atomic_order_seq_cst define"
#endif
#ifdef __opencl_c_atomic_scope_device
#error "Incorrect feature macro __opencl_c_atomic_scope_device define"
#endif
#ifdef __opencl_c_atomic_scope_all_devices
#error "Incorrect feature macro __opencl_c_atomic_scope_all_devices define"
#endif
#ifdef __opencl_c_device_enqueue
#error "Incorrect feature macro __opencl_c_device_enqueue define"
#endif
#ifdef __opencl_c_read_write_images
#error "Incorrect feature macro __opencl_c_read_write_images define"
#endif
#ifdef __opencl_c_program_scope_global_variables
#error "Incorrect feature macro __opencl_c_program_scope_global_variables define"
#endif
#ifdef __opencl_c_images
#error "Incorrect feature macro __opencl_c_images define"
#endif
#ifdef __opencl_c_3d_image_writes
#error "Incorrect feature macro __opencl_c_3d_image_writes define"
#endif
#ifdef __opencl_c_fp64
#error "Incorrect feature macro __opencl_c_fp64 define"
#endif
#ifdef __opencl_c_subgroups
#error "Incorrect feature macro __opencl_c_subgroups define"
#endif

#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)

#endif // defined(__SPIR__)