Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/test/transcoding/OpenCL/barrier.cl

raw
1 // RUN: %clang_cc1 %s -triple spir -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header -emit-llvm-bc -o %t.bc
2 // RUN: llvm-spirv %t.bc -o %t.spv
3 // RUN: spirv-val %t.spv
4 // RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
5 // RUN: llvm-spirv %t.spv -r -emit-opaque-pointers --spirv-target-env=CL1.2 -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM
6
7 // This test checks that the translator is capable to correctly translate
8 // barrier OpenCL C 1.2 built-in function [1] into corresponding SPIR-V
9 // instruction and vice-versa.
10
11 // FIXME: Strictly speaking, this flag is not supported by barrier in OpenCL 1.2
12 #define CLK_IMAGE_MEM_FENCE 0x04
13
14 void __attribute__((overloadable)) __attribute__((convergent)) barrier(cl_mem_fence_flags);
15
16 __kernel void test_barrier_const_flags() {
17 barrier(CLK_LOCAL_MEM_FENCE);
18 barrier(CLK_GLOBAL_MEM_FENCE);
19 barrier(CLK_IMAGE_MEM_FENCE);
20
21 barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
22 barrier(CLK_LOCAL_MEM_FENCE | CLK_IMAGE_MEM_FENCE);
23 barrier(CLK_GLOBAL_MEM_FENCE | CLK_LOCAL_MEM_FENCE | CLK_IMAGE_MEM_FENCE);
24 }
25
26 __kernel void test_barrier_non_const_flags(cl_mem_fence_flags flags) {
27 // FIXME: OpenCL spec doesn't require flags to be compile-time known
28 // barrier(flags);
29 }
30
31 // CHECK-SPIRV: Name [[TEST_CONST_FLAGS:[0-9]+]] "test_barrier_const_flags"
32 // CHECK-SPIRV: TypeInt [[UINT:[0-9]+]] 32 0
33 //
34 // In SPIR-V, barrier is represented as OpControlBarrier [3] and OpenCL
35 // cl_mem_fence_flags are represented as part of Memory Semantics [2], which
36 // also includes memory order constraints. The translator applies some default
37 // memory order for OpControlBarrier and therefore, constants below include a
38 // bit more information than original source
39 //
40 // 0x2 Workgroup
41 // CHECK-SPIRV-DAG: Constant [[UINT]] [[WG:[0-9]+]] 2
42 //
43 // 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory
44 // CHECK-SPIRV-DAG: Constant [[UINT]] [[LOCAL:[0-9]+]] 272
45 // 0x10 SequentiallyConsistent + 0x200 CrossWorkgroupMemory
46 // CHECK-SPIRV-DAG: Constant [[UINT]] [[GLOBAL:[0-9]+]] 528
47 // 0x10 SequentiallyConsistent + 0x800 ImageMemory
48 // CHECK-SPIRV-DAG: Constant [[UINT]] [[IMAGE:[0-9]+]] 2064
49 // 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory
50 // CHECK-SPIRV-DAG: Constant [[UINT]] [[LOCAL_GLOBAL:[0-9]+]] 784
51 // 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x800 ImageMemory
52 // CHECK-SPIRV-DAG: Constant [[UINT]] [[LOCAL_IMAGE:[0-9]+]] 2320
53 // 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory + 0x800 ImageMemory
54 // CHECK-SPIRV-DAG: Constant [[UINT]] [[LOCAL_GLOBAL_IMAGE:[0-9]+]] 2832
55 //
56 // CHECK-SPIRV: Function {{[0-9]+}} [[TEST_CONST_FLAGS]]
57 // CHECK-SPIRV: ControlBarrier [[WG]] [[WG]] [[LOCAL]]
58 // CHECK-SPIRV: ControlBarrier [[WG]] [[WG]] [[GLOBAL]]
59 // CHECK-SPIRV: ControlBarrier [[WG]] [[WG]] [[IMAGE]]
60 // CHECK-SPIRV: ControlBarrier [[WG]] [[WG]] [[LOCAL_GLOBAL]]
61 // CHECK-SPIRV: ControlBarrier [[WG]] [[WG]] [[LOCAL_IMAGE]]
62 // CHECK-SPIRV: ControlBarrier [[WG]] [[WG]] [[LOCAL_GLOBAL_IMAGE]]
63 //
64 // CHECK-LLVM-LABEL: define spir_kernel void @test_barrier_const_flags
65 // CHECK-LLVM: call spir_func void @_Z7barrierj(i32 1)
66 // CHECK-LLVM: call spir_func void @_Z7barrierj(i32 2)
67 // CHECK-LLVM: call spir_func void @_Z7barrierj(i32 4)
68 // CHECK-LLVM: call spir_func void @_Z7barrierj(i32 3)
69 // CHECK-LLVM: call spir_func void @_Z7barrierj(i32 5)
70 // CHECK-LLVM: call spir_func void @_Z7barrierj(i32 7)
71
72 // References:
73 // [1]: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
74 // [2]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_memory_semantics__id_a_memory_semantics_lt_id_gt
75 // [3]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpControlBarrier