Skip to content

Commit 9514a77

Browse files
authored
[SPIR-V] [NFC] Verify cl_intel_subgroup_local_block_io extension in SPIR-V BE (llvm#118796)
This OpenCL extension extends the subgroup block read and write functions defined by `cl_intel_subgroups` (and its `char`, `short`, and `long` versions) to support reading from and writing to pointers to the` __local` memory address space in addition to pointers to the `__global` memory address space. The builtins are translated to SPIR-V using `SPV_INTEL_subgroups` extension.
1 parent eaa1b05 commit 9514a77

File tree

3 files changed

+159
-6
lines changed

3 files changed

+159
-6
lines changed

llvm/lib/Target/SPIRV/SPIRVBuiltins.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,10 +1197,10 @@ defm : DemangledIntelSubgroupsBuiltin<"shuffle_down", 3, 3, OpSubgroupShuffleDow
11971197
defm : DemangledIntelSubgroupsBuiltin<"shuffle_up", 3, 3, OpSubgroupShuffleUpINTEL>;
11981198
defm : DemangledIntelSubgroupsBuiltin<"shuffle_xor", 2, 2, OpSubgroupShuffleXorINTEL>;
11991199
foreach i = ["", "2", "4", "8"] in {
1200-
// cl_intel_subgroups
1200+
// cl_intel_subgroups, cl_intel_subgroup_local_block_io
12011201
defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read", i), 1, 2, OpSubgroupBlockReadINTEL>;
12021202
defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_write", i), 2, 3, OpSubgroupBlockWriteINTEL>;
1203-
// cl_intel_subgroups_short
1203+
// cl_intel_subgroups_short, cl_intel_subgroup_local_block_io
12041204
defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read_ui", i), 1, 2, OpSubgroupBlockReadINTEL>;
12051205
defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_write_ui", i), 2, 3, OpSubgroupBlockWriteINTEL>;
12061206
// cl_intel_media_block_io
@@ -1209,7 +1209,7 @@ foreach i = ["", "2", "4", "8"] in {
12091209
defm : DemangledIntelSubgroupsBuiltin<!strconcat("media_block_write", i), 5, 5, OpSubgroupImageMediaBlockWriteINTEL>;
12101210
defm : DemangledIntelSubgroupsBuiltin<!strconcat("media_block_write_ui", i), 5, 5, OpSubgroupImageMediaBlockWriteINTEL>;
12111211
}
1212-
// cl_intel_subgroups_char, cl_intel_subgroups_short, cl_intel_subgroups_long, cl_intel_media_block_io
1212+
// cl_intel_subgroups_char, cl_intel_subgroups_short, cl_intel_subgroups_long, cl_intel_media_block_io, cl_intel_subgroup_local_block_io
12131213
foreach i = ["", "2", "4", "8", "16"] in {
12141214
foreach j = ["c", "s", "l"] in {
12151215
defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read_u", j, i), 1, 2, OpSubgroupBlockReadINTEL>;

llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_subgroups/cl_intel_sub_groups.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@
7777

7878
; CHECK-SPIRV-LABEL: Return
7979

80-
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
81-
target triple = "spir64"
82-
8380
%opencl.image2d_ro_t = type opaque
8481
%opencl.image2d_wo_t = type opaque
8582

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
; Modified from: https://github.com/KhronosGroup/SPIRV-LLVM-Translator/test/extensions/INTEL/SPV_INTEL_subgroups/cl_intel_sub_groups.ll
2+
3+
;Source:
4+
;void __kernel test(float2 x, uint c,
5+
; read_only image2d_t image_in,
6+
; write_only image2d_t image_out,
7+
; int2 coord,
8+
; __local uint* p,
9+
; __local ushort* sp,
10+
; __local uchar* cp,
11+
; __local ulong* lp) {
12+
;
13+
; uint2 ui2 = intel_sub_group_block_read2(image_in, coord);
14+
; intel_sub_group_block_write2(image_out, coord, ui2);
15+
; ui2 = intel_sub_group_block_read2(p);
16+
; intel_sub_group_block_write2(p, ui2);
17+
;
18+
; ushort2 us2 = intel_sub_group_block_read_us2(image_in, coord);
19+
; intel_sub_group_block_write_us2(image_out, coord, us2);
20+
; us2 = intel_sub_group_block_read_us2(sp);
21+
; intel_sub_group_block_write_us2(sp, us2);
22+
;
23+
; uchar2 uc2 = intel_sub_group_block_read_uc2(image_in, coord);
24+
; intel_sub_group_block_write_uc2(image_out, coord, uc2);
25+
; uc2 = intel_sub_group_block_read_uc2(cp);
26+
; intel_sub_group_block_write_uc2(cp, uc2);
27+
;
28+
; ulong2 ul2 = intel_sub_group_block_read_ul2(image_in, coord);
29+
; intel_sub_group_block_write_ul2(image_out, coord, ul2);
30+
; ul2 = intel_sub_group_block_read_ul2(lp);
31+
; intel_sub_group_block_write_ul2(lp, ul2);
32+
;}
33+
34+
; RUN: not llc -O0 -mtriple=spirv32-unknown-unknown %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
35+
36+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_subgroups %s -o - | FileCheck %s
37+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_subgroups %s -o - -filetype=obj | spirv-val %}
38+
39+
; CHECK-ERROR: LLVM ERROR: intel_sub_group_block_read2: the builtin requires the following SPIR-V extension: SPV_INTEL_subgroups
40+
41+
; CHECK-DAG: Capability SubgroupBufferBlockIOINTEL
42+
; CHECK-DAG: Capability SubgroupImageBlockIOINTEL
43+
; CHECK: Extension "SPV_INTEL_subgroups"
44+
45+
; CHECK-SPIRV-LABEL: Function
46+
; CHECK-SPIRV-LABEL: Label
47+
48+
; CHECK: SubgroupImageBlockReadINTEL
49+
; CHECK: SubgroupImageBlockWriteINTEL
50+
; CHECK: SubgroupBlockReadINTEL
51+
; CHECK: SubgroupBlockWriteINTEL
52+
53+
; CHECK: SubgroupImageBlockReadINTEL
54+
; CHECK: SubgroupImageBlockWriteINTEL
55+
; CHECK: SubgroupBlockReadINTEL
56+
; CHECK: SubgroupBlockWriteINTEL
57+
58+
; CHECK: SubgroupImageBlockReadINTEL
59+
; CHECK: SubgroupImageBlockWriteINTEL
60+
; CHECK: SubgroupBlockReadINTEL
61+
; CHECK: SubgroupBlockWriteINTEL
62+
63+
; CHECK: SubgroupImageBlockReadINTEL
64+
; CHECK: SubgroupImageBlockWriteINTEL
65+
; CHECK: SubgroupBlockReadINTEL
66+
; CHECK: SubgroupBlockWriteINTEL
67+
68+
; CHECK-SPIRV-LABEL: Return
69+
70+
%opencl.image2d_ro_t = type opaque
71+
%opencl.image2d_wo_t = type opaque
72+
73+
; Function Attrs: convergent nounwind
74+
define spir_kernel void @test(<2 x float> %x, i32 %c, ptr addrspace(3) %image_in, ptr addrspace(3) %image_out, <2 x i32> %coord, ptr addrspace(3) %p, ptr addrspace(3) %sp, ptr addrspace(3) %cp, ptr addrspace(3) %lp) !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 !kernel_arg_name !6 {
75+
entry:
76+
%call4 = tail call spir_func <2 x i32> @_Z27intel_sub_group_block_read214ocl_image2d_roDv2_i(ptr addrspace(3) %image_in, <2 x i32> %coord)
77+
tail call spir_func void @_Z28intel_sub_group_block_write214ocl_image2d_woDv2_iDv2_j(ptr addrspace(3) %image_out, <2 x i32> %coord, <2 x i32> %call4)
78+
%call5 = tail call spir_func <2 x i32> @_Z27intel_sub_group_block_read2PU3AS1Kj(ptr addrspace(3) %p)
79+
tail call spir_func void @_Z28intel_sub_group_block_write2PU3AS1jDv2_j(ptr addrspace(3) %p, <2 x i32> %call5)
80+
81+
%call6 = tail call spir_func <2 x i16> @_Z30intel_sub_group_block_read_us214ocl_image2d_roDv2_i(ptr addrspace(3) %image_in, <2 x i32> %coord)
82+
tail call spir_func void @_Z31intel_sub_group_block_write_us214ocl_image2d_woDv2_iDv2_t(ptr addrspace(3) %image_out, <2 x i32> %coord, <2 x i16> %call6)
83+
%call7 = tail call spir_func <2 x i16> @_Z30intel_sub_group_block_read_us2PU3AS1Kt(ptr addrspace(3) %sp)
84+
tail call spir_func void @_Z31intel_sub_group_block_write_us2PU3AS1tDv2_t(ptr addrspace(3) %sp, <2 x i16> %call7)
85+
86+
%call8 = tail call spir_func <2 x i8> @_Z30intel_sub_group_block_read_uc214ocl_image2d_roDv2_i(ptr addrspace(3) %image_in, <2 x i32> %coord)
87+
tail call spir_func void @_Z31intel_sub_group_block_write_uc214ocl_image2d_woDv2_iDv2_h(ptr addrspace(3) %image_out, <2 x i32> %coord, <2 x i8> %call8)
88+
%call9 = tail call spir_func <2 x i8> @_Z30intel_sub_group_block_read_uc2PU3AS1Kh(ptr addrspace(3) %cp)
89+
tail call spir_func void @_Z31intel_sub_group_block_write_uc2PU3AS1hDv2_h(ptr addrspace(3) %cp, <2 x i8> %call9)
90+
91+
%call10 = tail call spir_func <2 x i64> @_Z30intel_sub_group_block_read_ul214ocl_image2d_roDv2_i(ptr addrspace(3) %image_in, <2 x i32> %coord)
92+
tail call spir_func void @_Z31intel_sub_group_block_write_ul214ocl_image2d_woDv2_iDv2_m(ptr addrspace(3) %image_out, <2 x i32> %coord, <2 x i64> %call10)
93+
%call11 = tail call spir_func <2 x i64> @_Z30intel_sub_group_block_read_ul2PU3AS1Km(ptr addrspace(3) %lp)
94+
tail call spir_func void @_Z31intel_sub_group_block_write_ul2PU3AS1mDv2_m(ptr addrspace(3) %lp, <2 x i64> %call11)
95+
96+
ret void
97+
}
98+
99+
; Function Attrs: convergent
100+
declare spir_func <2 x i32> @_Z27intel_sub_group_block_read214ocl_image2d_roDv2_i(ptr addrspace(3), <2 x i32>)
101+
102+
; Function Attrs: convergent
103+
declare spir_func void @_Z28intel_sub_group_block_write214ocl_image2d_woDv2_iDv2_j(ptr addrspace(3), <2 x i32>, <2 x i32>)
104+
105+
; Function Attrs: convergent
106+
declare spir_func <2 x i32> @_Z27intel_sub_group_block_read2PU3AS1Kj(ptr addrspace(3))
107+
108+
; Function Attrs: convergent
109+
declare spir_func void @_Z28intel_sub_group_block_write2PU3AS1jDv2_j(ptr addrspace(3), <2 x i32>)
110+
111+
; Function Attrs: convergent
112+
declare spir_func <2 x i16> @_Z30intel_sub_group_block_read_us214ocl_image2d_roDv2_i(ptr addrspace(3), <2 x i32>)
113+
114+
; Function Attrs: convergent
115+
declare spir_func void @_Z31intel_sub_group_block_write_us214ocl_image2d_woDv2_iDv2_t(ptr addrspace(3), <2 x i32>, <2 x i16>)
116+
117+
; Function Attrs: convergent
118+
declare spir_func <2 x i16> @_Z30intel_sub_group_block_read_us2PU3AS1Kt(ptr addrspace(3))
119+
120+
; Function Attrs: convergent
121+
declare spir_func void @_Z31intel_sub_group_block_write_us2PU3AS1tDv2_t(ptr addrspace(3), <2 x i16>)
122+
123+
; Function Attrs: convergent
124+
declare spir_func <2 x i8> @_Z30intel_sub_group_block_read_uc214ocl_image2d_roDv2_i(ptr addrspace(3), <2 x i32>)
125+
126+
; Function Attrs: convergent
127+
declare spir_func void @_Z31intel_sub_group_block_write_uc214ocl_image2d_woDv2_iDv2_h(ptr addrspace(3), <2 x i32>, <2 x i8>)
128+
129+
; Function Attrs: convergent
130+
declare spir_func <2 x i8> @_Z30intel_sub_group_block_read_uc2PU3AS1Kh(ptr addrspace(3))
131+
132+
; Function Attrs: convergent
133+
declare spir_func void @_Z31intel_sub_group_block_write_uc2PU3AS1hDv2_h(ptr addrspace(3), <2 x i8>)
134+
135+
; Function Attrs: convergent
136+
declare spir_func <2 x i64> @_Z30intel_sub_group_block_read_ul214ocl_image2d_roDv2_i(ptr addrspace(3), <2 x i32>)
137+
138+
; Function Attrs: convergent
139+
declare spir_func void @_Z31intel_sub_group_block_write_ul214ocl_image2d_woDv2_iDv2_m(ptr addrspace(3), <2 x i32>, <2 x i64>)
140+
141+
; Function Attrs: convergent
142+
declare spir_func <2 x i64> @_Z30intel_sub_group_block_read_ul2PU3AS1Km(ptr addrspace(3))
143+
144+
; Function Attrs: convergent
145+
declare spir_func void @_Z31intel_sub_group_block_write_ul2PU3AS1mDv2_m(ptr addrspace(3), <2 x i64>)
146+
147+
!opencl.ocl.version = !{!0}
148+
!opencl.spir.version = !{!0}
149+
150+
!0 = !{i32 1, i32 2}
151+
!1 = !{i32 0, i32 0, i32 1, i32 1, i32 0, i32 1, i32 1, i32 1, i32 1}
152+
!2 = !{!"none", !"none", !"read_only", !"write_only", !"none", !"none", !"none", !"none", !"none"}
153+
!3 = !{!"float2", !"uint", !"image2d_t", !"image2d_t", !"int2", !"uint*", !"ushort*", !"uchar*", !"ulong*"}
154+
!4 = !{!"float __attribute__((ext_vector_type(2)))", !"uint", !"image2d_t", !"image2d_t", !"int __attribute__((ext_vector_type(2)))", !"uint*", !"ushort*", !"uchar*", !"ulong*"}
155+
!5 = !{!"", !"", !"", !"", !"", !"", !"", !"", !""}
156+
!6 = !{!"x", !"c", !"image_in", !"image_out", !"coord", !"p", !"sp", !"cp", !"lp"}

0 commit comments

Comments
 (0)