1 // RUN: mlir-opt -split-input-file -convert-gpu-to-spirv="use-64bit-index=false" %s -o - | FileCheck %s --check-prefix=INDEX32
2 // RUN: mlir-opt -split-input-file -convert-gpu-to-spirv="use-64bit-index=true" %s -o - | FileCheck %s --check-prefix=INDEX64
6 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
9 %c0 = arith.constant 1 : index
10 gpu.launch_func @kernels::@builtin_workgroup_id_x
11 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
15 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
16 // INDEX32: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") : !spirv.ptr<vector<3xi32>, Input>
17 // INDEX64-LABEL: spirv.module @{{.*}} Logical GLSL450
18 // INDEX64: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") : !spirv.ptr<vector<3xi32>, Input>
20 gpu.func @builtin_workgroup_id_x() kernel
21 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
22 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]]
23 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
24 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}}
25 // INDEX64: spirv.UConvert %{{.+}} : i32 to i64
36 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
38 func.func @builtin() {
39 %c0 = arith.constant 1 : index
40 %c256 = arith.constant 256 : i32
41 gpu.launch_func @kernels::@builtin_workgroup_id_y
42 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
43 dynamic_shared_memory_size %c256
47 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
48 // INDEX32: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") : !spirv.ptr<vector<3xi32>, Input>
50 gpu.func @builtin_workgroup_id_y() kernel
51 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
52 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]]
53 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
54 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}}
65 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
67 func.func @builtin() {
68 %c0 = arith.constant 1 : index
69 gpu.launch_func @kernels::@builtin_workgroup_id_z
70 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
74 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
75 // INDEX32: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") : !spirv.ptr<vector<3xi32>, Input>
77 gpu.func @builtin_workgroup_id_z() kernel
78 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
79 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]]
80 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
81 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}}
92 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
94 func.func @builtin() {
95 %c0 = arith.constant 1 : index
96 gpu.launch_func @kernels::@builtin_workgroup_size_x
97 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
101 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
102 gpu.module @kernels {
103 gpu.func @builtin_workgroup_size_x() kernel
104 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [32, 1, 1]>} {
105 // The constant value is obtained from the spirv.entry_point_abi.
106 // Note that this ignores the workgroup size specification in gpu.launch.
107 // We may want to define gpu.workgroup_size and convert it to the entry
108 // point ABI we want here.
109 // INDEX32: spirv.Constant 32 : i32
119 gpu.container_module,
120 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
122 func.func @builtin() {
123 %c0 = arith.constant 1 : index
124 gpu.launch_func @kernels::@builtin_workgroup_size_y
125 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
129 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
130 gpu.module @kernels {
131 gpu.func @builtin_workgroup_size_y() kernel
132 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [32, 4, 1]>} {
133 // The constant value is obtained from the spirv.entry_point_abi.
134 // INDEX32: spirv.Constant 4 : i32
144 gpu.container_module,
145 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
147 func.func @builtin() {
148 %c0 = arith.constant 1 : index
149 gpu.launch_func @kernels::@builtin_workgroup_size_z
150 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
154 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
155 gpu.module @kernels {
156 gpu.func @builtin_workgroup_size_z() kernel
157 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [32, 4, 1]>} {
158 // The constant value is obtained from the spirv.entry_point_abi.
159 // INDEX32: spirv.Constant 1 : i32
169 gpu.container_module,
170 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
172 func.func @builtin() {
173 %c0 = arith.constant 1 : index
174 gpu.launch_func @kernels::@builtin_local_id_x
175 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
179 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
180 // INDEX32: spirv.GlobalVariable [[LOCALINVOCATIONID:@.*]] built_in("LocalInvocationId") : !spirv.ptr<vector<3xi32>, Input>
181 gpu.module @kernels {
182 gpu.func @builtin_local_id_x() kernel
183 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
184 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[LOCALINVOCATIONID]]
185 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
186 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}}
196 gpu.container_module,
197 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
199 func.func @builtin() {
200 %c0 = arith.constant 1 : index
201 gpu.launch_func @kernels::@builtin_num_workgroups_x
202 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
206 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
207 // INDEX32: spirv.GlobalVariable [[NUMWORKGROUPS:@.*]] built_in("NumWorkgroups") : !spirv.ptr<vector<3xi32>, Input>
208 gpu.module @kernels {
209 gpu.func @builtin_num_workgroups_x() kernel
210 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
211 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[NUMWORKGROUPS]]
212 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
213 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}}
223 gpu.container_module,
224 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
226 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
227 // INDEX32: spirv.GlobalVariable [[SUBGROUPID:@.*]] built_in("SubgroupId") : !spirv.ptr<i32, Input>
228 gpu.module @kernels {
229 gpu.func @builtin_subgroup_id() kernel
230 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
231 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[SUBGROUPID]]
232 // INDEX32-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]]
233 %0 = gpu.subgroup_id : index
242 gpu.container_module,
243 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
245 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
246 // INDEX32: spirv.GlobalVariable [[NUMSUBGROUPS:@.*]] built_in("NumSubgroups") : !spirv.ptr<i32, Input>
247 gpu.module @kernels {
248 gpu.func @builtin_num_subgroups() kernel
249 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
250 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[NUMSUBGROUPS]]
251 // INDEX32-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]]
252 %0 = gpu.num_subgroups : index
261 gpu.container_module,
262 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
264 func.func @builtin() {
265 %c0 = arith.constant 1 : index
266 gpu.launch_func @kernels::@builtin_workgroup_size_x
267 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
271 // INDEX32-LABEL: spirv.module @{{.*}}
272 // INDEX32: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") : !spirv.ptr<vector<3xi32>, Input>
273 gpu.module @kernels {
274 gpu.func @builtin_workgroup_size_x() kernel
275 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
276 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]]
277 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
278 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}}
288 gpu.container_module,
289 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
291 func.func @builtin() {
292 %c0 = arith.constant 1 : index
293 gpu.launch_func @kernels::@builtin_workgroup_size_y
294 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
298 // INDEX32-LABEL: spirv.module @{{.*}}
299 // INDEX32: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") : !spirv.ptr<vector<3xi32>, Input>
300 gpu.module @kernels {
301 gpu.func @builtin_workgroup_size_y() kernel
302 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
303 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]]
304 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
305 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}}
315 gpu.container_module,
316 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
318 func.func @builtin() {
319 %c0 = arith.constant 1 : index
320 gpu.launch_func @kernels::@builtin_workgroup_size_z
321 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
325 // INDEX32-LABEL: spirv.module @{{.*}}
326 // INDEX32: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") : !spirv.ptr<vector<3xi32>, Input>
327 gpu.module @kernels {
328 gpu.func @builtin_workgroup_size_z() kernel
329 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} {
330 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]]
331 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
332 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}}
342 gpu.container_module,
343 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
345 func.func @builtin() {
346 %c0 = arith.constant 1 : index
347 gpu.launch_func @kernels::@builtin_global_id_x
348 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
352 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
353 // INDEX32: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") : !spirv.ptr<vector<3xi32>, Input>
354 gpu.module @kernels {
355 gpu.func @builtin_global_id_x() kernel
356 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
357 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]]
358 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
359 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}}
369 gpu.container_module,
370 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
372 func.func @builtin() {
373 %c0 = arith.constant 1 : index
374 gpu.launch_func @kernels::@builtin_global_id_y
375 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
379 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
380 // INDEX32: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") : !spirv.ptr<vector<3xi32>, Input>
381 gpu.module @kernels {
382 gpu.func @builtin_global_id_y() kernel
383 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
384 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]]
385 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
386 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}}
396 gpu.container_module,
397 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
399 func.func @builtin() {
400 %c0 = arith.constant 1 : index
401 gpu.launch_func @kernels::@builtin_global_id_z
402 blocks in (%c0, %c0, %c0) threads in (%c0, %c0, %c0)
406 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
407 // INDEX32: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") : !spirv.ptr<vector<3xi32>, Input>
408 gpu.module @kernels {
409 gpu.func @builtin_global_id_z() kernel
410 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
411 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]]
412 // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]]
413 // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}}
424 gpu.container_module,
425 spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Shader, Int64], []>, #spirv.resource_limits<>>
427 // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450
428 // INDEX32: spirv.GlobalVariable [[SUBGROUPSIZE:@.*]] built_in("SubgroupSize") : !spirv.ptr<i32, Input>
429 // INDEX64-LABEL: spirv.module @{{.*}} Logical GLSL450
430 // INDEX64: spirv.GlobalVariable [[SUBGROUPSIZE:@.*]] built_in("SubgroupSize") : !spirv.ptr<i32, Input>
431 gpu.module @kernels {
432 gpu.func @builtin_subgroup_size() kernel
433 attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} {
434 // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[SUBGROUPSIZE]]
435 // INDEX32-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]]
436 // INDEX64: spirv.UConvert %{{.+}} : i32 to i64
437 %0 = gpu.subgroup_size : index