| 1 |
// Pipe built-ins are mangled accordingly to SPIR2.0/C++ ABI. |
| 2 |
|
| 3 |
// RUN: %clang_cc1 -x cl -cl-std=CL2.0 -triple spir64-unknown-unknown -emit-llvm-bc -fdeclare-opencl-builtins -finclude-default-header -Dcl_khr_subgroups %s -o %t.bc -no-opaque-pointers |
| 4 |
// RUN: llvm-spirv %t.bc -opaque-pointers=0 -spirv-text -o %t.spt |
| 5 |
// RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV |
| 6 |
// RUN: llvm-spirv %t.bc -opaque-pointers=0 -o %t.spv |
| 7 |
// RUN: spirv-val %t.spv |
| 8 |
// RUN: llvm-spirv -r %t.spv -o %t.bc |
| 9 |
// RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-LLVM |
| 10 |
|
| 11 |
// CHECK-SPIRV-DAG: TypePipe [[ROPipeTy:[0-9]+]] 0 |
| 12 |
// CHECK-SPIRV-DAG: TypePipe [[WOPipeTy:[0-9]+]] 1 |
| 13 |
|
| 14 |
#pragma OPENCL EXTENSION cl_khr_subgroups : enable |
| 15 |
|
| 16 |
// CHECK-LLVM-LABEL: @test_pipe_convenience_write_uint |
| 17 |
__kernel void test_pipe_convenience_write_uint(__global uint *src, __write_only pipe uint out_pipe) |
| 18 |
{ |
| 19 |
// CHECK-SPIRV: 5 Function |
| 20 |
// CHECK-SPIRV-NEXT: FunctionParameter |
| 21 |
// CHECK-SPIRV-NEXT: FunctionParameter [[WOPipeTy]] [[PipeArgID:[0-9]+]] |
| 22 |
// CHECK-LLVM: call{{.*}}@__write_pipe_2 |
| 23 |
// CHECK-SPIRV: WritePipe {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 24 |
// CHECK-SPIRV-LABEL: 1 FunctionEnd |
| 25 |
|
| 26 |
int gid = get_global_id(0); |
| 27 |
write_pipe(out_pipe, &src[gid]); |
| 28 |
} |
| 29 |
|
| 30 |
// CHECK-LLVM-LABEL: @test_pipe_convenience_read_uint |
| 31 |
// CHECK-SPIRV-LABEL: 5 Function |
| 32 |
__kernel void test_pipe_convenience_read_uint(__read_only pipe uint in_pipe, __global uint *dst) |
| 33 |
{ |
| 34 |
// CHECK-SPIRV-NEXT: FunctionParameter [[ROPipeTy]] [[PipeArgID:[0-9]+]] |
| 35 |
// CHECK-LLVM: call{{.*}}@__read_pipe_2 |
| 36 |
// CHECK-SPIRV: ReadPipe {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 37 |
// CHECK-SPIRV-LABEL: 1 FunctionEnd |
| 38 |
|
| 39 |
int gid = get_global_id(0); |
| 40 |
read_pipe(in_pipe, &dst[gid]); |
| 41 |
} |
| 42 |
|
| 43 |
// CHECK-LLVM-LABEL: @test_pipe_write |
| 44 |
// CHECK-SPIRV-LABEL: 5 Function |
| 45 |
__kernel void test_pipe_write(__global int *src, __write_only pipe int out_pipe) |
| 46 |
{ |
| 47 |
// CHECK-SPIRV-NEXT: FunctionParameter |
| 48 |
// CHECK-SPIRV-NEXT: FunctionParameter [[WOPipeTy]] [[PipeArgID:[0-9]+]] |
| 49 |
// CHECK-LLVM: @__reserve_write_pipe |
| 50 |
// CHECK-SPIRV: ReserveWritePipePackets {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 51 |
// CHECK-LLVM: call{{.*}}@__write_pipe_4 |
| 52 |
// CHECK-SPIRV: ReservedWritePipe {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 53 |
// CHECK-LLVM: call{{.*}}@__commit_write_pipe |
| 54 |
// CHECK-SPIRV: CommitWritePipe [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} |
| 55 |
// CHECK-SPIRV-LABEL: 1 FunctionEnd |
| 56 |
|
| 57 |
int gid = get_global_id(0); |
| 58 |
reserve_id_t res_id; |
| 59 |
res_id = reserve_write_pipe(out_pipe, 1); |
| 60 |
if(is_valid_reserve_id(res_id)) |
| 61 |
{ |
| 62 |
write_pipe(out_pipe, res_id, 0, &src[gid]); |
| 63 |
commit_write_pipe(out_pipe, res_id); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
// CHECK-LLVM-LABEL: @test_pipe_query_functions |
| 68 |
// CHECK-SPIRV-LABEL: 5 Function |
| 69 |
__kernel void test_pipe_query_functions(__write_only pipe int out_pipe, __global int *num_packets, __global int *max_packets) |
| 70 |
{ |
| 71 |
// CHECK-SPIRV-NEXT: FunctionParameter [[WOPipeTy]] [[PipeArgID:[0-9]+]] |
| 72 |
// CHECK-LLVM: call{{.*}}@__get_pipe_max_packets_wo |
| 73 |
// CHECK-SPIRV: GetMaxPipePackets {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} |
| 74 |
// CHECK-LLVM: call{{.*}}@__get_pipe_num_packets |
| 75 |
// CHECK-SPIRV: GetNumPipePackets {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} |
| 76 |
// CHECK-SPIRV-LABEL: 1 FunctionEnd |
| 77 |
|
| 78 |
*max_packets = get_pipe_max_packets(out_pipe); |
| 79 |
*num_packets = get_pipe_num_packets(out_pipe); |
| 80 |
} |
| 81 |
|
| 82 |
// CHECK-LLVM-LABEL: @test_pipe_read |
| 83 |
// CHECK-SPIRV-LABEL: 5 Function |
| 84 |
__kernel void test_pipe_read(__read_only pipe int in_pipe, __global int *dst) |
| 85 |
{ |
| 86 |
// CHECK-SPIRV-NEXT: FunctionParameter [[ROPipeTy]] [[PipeArgID:[0-9]+]] |
| 87 |
// CHECK-LLVM: call{{.*}}@__reserve_read_pipe |
| 88 |
// CHECK-SPIRV: ReserveReadPipePackets {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 89 |
// CHECK-LLVM: call{{.*}}@__read_pipe_4 |
| 90 |
// CHECK-SPIRV: ReservedReadPipe {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 91 |
// CHECK-LLVM: call{{.*}}@__commit_read_pipe |
| 92 |
// CHECK-SPIRV: CommitReadPipe [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 93 |
// CHECK-SPIRV-LABEL: 1 FunctionEnd |
| 94 |
|
| 95 |
int gid = get_global_id(0); |
| 96 |
reserve_id_t res_id; |
| 97 |
res_id = reserve_read_pipe(in_pipe, 1); |
| 98 |
if(is_valid_reserve_id(res_id)) |
| 99 |
{ |
| 100 |
read_pipe(in_pipe, res_id, 0, &dst[gid]); |
| 101 |
commit_read_pipe(in_pipe, res_id); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
// CHECK-LLVM-LABEL: @test_pipe_workgroup_write_char |
| 106 |
// CHECK-SPIRV-LABEL: 5 Function |
| 107 |
__kernel void test_pipe_workgroup_write_char(__global char *src, __write_only pipe char out_pipe) |
| 108 |
{ |
| 109 |
// CHECK-SPIRV-NEXT: FunctionParameter |
| 110 |
// CHECK-SPIRV-NEXT: FunctionParameter [[WOPipeTy]] [[PipeArgID:[0-9]+]] |
| 111 |
// CHECK-LLVM: call{{.*}}@__work_group_reserve_write_pipe |
| 112 |
// CHECK-SPIRV: GroupReserveWritePipePackets {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 113 |
// CHECK-LLVM: call{{.*}}@__work_group_commit_write_pipe |
| 114 |
// CHECK-SPIRV: GroupCommitWritePipe {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 115 |
// CHECK-SPIRV-LABEL: 1 FunctionEnd |
| 116 |
|
| 117 |
int gid = get_global_id(0); |
| 118 |
__local reserve_id_t res_id; |
| 119 |
|
| 120 |
res_id = work_group_reserve_write_pipe(out_pipe, get_local_size(0)); |
| 121 |
if(is_valid_reserve_id(res_id)) |
| 122 |
{ |
| 123 |
write_pipe(out_pipe, res_id, get_local_id(0), &src[gid]); |
| 124 |
work_group_commit_write_pipe(out_pipe, res_id); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
// CHECK-LLVM-LABEL: @test_pipe_workgroup_read_char |
| 129 |
// CHECK-SPIRV-LABEL: 5 Function |
| 130 |
__kernel void test_pipe_workgroup_read_char(__read_only pipe char in_pipe, __global char *dst) |
| 131 |
{ |
| 132 |
// CHECK-SPIRV-NEXT: FunctionParameter [[ROPipeTy]] [[PipeArgID:[0-9]+]] |
| 133 |
// CHECK-LLVM: call{{.*}}@__work_group_reserve_read_pipe |
| 134 |
// CHECK-SPIRV: GroupReserveReadPipePackets {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 135 |
// CHECK-LLVM: call{{.*}}@__work_group_commit_read_pipe |
| 136 |
// CHECK-SPIRV: GroupCommitReadPipe {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 137 |
// CHECK-SPIRV-LABEL: 1 FunctionEnd |
| 138 |
|
| 139 |
int gid = get_global_id(0); |
| 140 |
__local reserve_id_t res_id; |
| 141 |
|
| 142 |
res_id = work_group_reserve_read_pipe(in_pipe, get_local_size(0)); |
| 143 |
if(is_valid_reserve_id(res_id)) |
| 144 |
{ |
| 145 |
read_pipe(in_pipe, res_id, get_local_id(0), &dst[gid]); |
| 146 |
work_group_commit_read_pipe(in_pipe, res_id); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
// CHECK-LLVM-LABEL: @test_pipe_subgroup_write_uint |
| 151 |
// CHECK-SPIRV-LABEL: 5 Function |
| 152 |
__kernel void test_pipe_subgroup_write_uint(__global uint *src, __write_only pipe uint out_pipe) |
| 153 |
{ |
| 154 |
// CHECK-SPIRV-NEXT: FunctionParameter |
| 155 |
// CHECK-SPIRV-NEXT: FunctionParameter [[WOPipeTy]] [[PipeArgID:[0-9]+]] |
| 156 |
// CHECK-LLVM: call{{.*}}@__sub_group_reserve_write_pipe |
| 157 |
// CHECK-SPIRV: GroupReserveWritePipePackets {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 158 |
// CHECK-LLVM: call{{.*}}@__sub_group_commit_write_pipe |
| 159 |
// CHECK-SPIRV: GroupCommitWritePipe {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 160 |
|
| 161 |
int gid = get_global_id(0); |
| 162 |
reserve_id_t res_id; |
| 163 |
|
| 164 |
res_id = sub_group_reserve_write_pipe(out_pipe, get_sub_group_size()); |
| 165 |
if(is_valid_reserve_id(res_id)) |
| 166 |
{ |
| 167 |
write_pipe(out_pipe, res_id, get_sub_group_local_id(), &src[gid]); |
| 168 |
sub_group_commit_write_pipe(out_pipe, res_id); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
// CHECK-LLVM-LABEL: @test_pipe_subgroup_read_uint |
| 173 |
// CHECK-SPIRV-LABEL: 5 Function |
| 174 |
__kernel void test_pipe_subgroup_read_uint(__read_only pipe uint in_pipe, __global uint *dst) |
| 175 |
{ |
| 176 |
// CHECK-SPIRV-NEXT: FunctionParameter [[ROPipeTy]] [[PipeArgID:[0-9]+]] |
| 177 |
// CHECK-LLVM: call{{.*}}@__sub_group_reserve_read_pipe |
| 178 |
// CHECK-SPIRV: GroupReserveReadPipePackets {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 179 |
// CHECK-LLVM: call{{.*}}@__sub_group_commit_read_pipe |
| 180 |
// CHECK-SPIRV: GroupCommitReadPipe {{[0-9]+}} [[PipeArgID]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} |
| 181 |
// CHECK-SPIRV-LABEL: 1 FunctionEnd |
| 182 |
|
| 183 |
int gid = get_global_id(0); |
| 184 |
reserve_id_t res_id; |
| 185 |
|
| 186 |
res_id = sub_group_reserve_read_pipe(in_pipe, get_sub_group_size()); |
| 187 |
if(is_valid_reserve_id(res_id)) |
| 188 |
{ |
| 189 |
read_pipe(in_pipe, res_id, get_sub_group_local_id(), &dst[gid]); |
| 190 |
sub_group_commit_read_pipe(in_pipe, res_id); |
| 191 |
} |
| 192 |
} |