diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td --- a/mlir/include/mlir/Conversion/Passes.td +++ b/mlir/include/mlir/Conversion/Passes.td @@ -476,6 +476,11 @@ }]; let constructor = "mlir::createConvertGPUToSPIRVPass()"; let dependentDialects = ["spirv::SPIRVDialect"]; + let options = [ + Option<"use64bitIndex", "use-64bit-index", + "bool", /*default=*/"false", + "Use 64-bit integers to convert index types"> + ]; } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp --- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp +++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp @@ -144,14 +144,31 @@ SourceOp op, typename SourceOp::Adaptor adaptor, ConversionPatternRewriter &rewriter) const { auto *typeConverter = this->template getTypeConverter(); - auto indexType = typeConverter->getIndexType(); - - // SPIR-V invocation builtin variables are a vector of type <3xi32> - auto spirvBuiltin = - spirv::getBuiltinVariableValue(op, builtin, indexType, rewriter); - rewriter.replaceOpWithNewOp( - op, indexType, spirvBuiltin, + Type indexType = typeConverter->getIndexType(); + + // For Vulkan, these SPIR-V builtin variables are required to be a vector of + // type <3xi32> by the spec: + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/NumWorkgroups.html + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/WorkgroupId.html + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/WorkgroupSize.html + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/LocalInvocationId.html + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/LocalInvocationId.html + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/GlobalInvocationId.html + // + // For OpenCL, it depends on the Physical32/Physical64 addressing model: + // https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Env.html#_built_in_variables + bool forShader = + typeConverter->getTargetEnv().allows(spirv::Capability::Shader); + Type builtinType = forShader ? rewriter.getIntegerType(32) : indexType; + + Value vector = + spirv::getBuiltinVariableValue(op, builtin, builtinType, rewriter); + Value dim = rewriter.create( + op.getLoc(), builtinType, vector, rewriter.getI32ArrayAttr({static_cast(op.getDimension())})); + if (forShader && builtinType != indexType) + dim = rewriter.create(op.getLoc(), indexType, dim); + rewriter.replaceOp(op, dim); return success(); } @@ -161,11 +178,23 @@ SourceOp op, typename SourceOp::Adaptor adaptor, ConversionPatternRewriter &rewriter) const { auto *typeConverter = this->template getTypeConverter(); - auto indexType = typeConverter->getIndexType(); - - auto spirvBuiltin = - spirv::getBuiltinVariableValue(op, builtin, indexType, rewriter); - rewriter.replaceOp(op, spirvBuiltin); + Type indexType = typeConverter->getIndexType(); + Type i32Type = rewriter.getIntegerType(32); + + // For Vulkan, these SPIR-V builtin variables are required to be a vector of + // type i32 by the spec: + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/NumSubgroups.html + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/SubgroupId.html + // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/SubgroupSize.html + // + // For OpenCL, they are also required to be i32: + // https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Env.html#_built_in_variables + Value builtinValue = + spirv::getBuiltinVariableValue(op, builtin, i32Type, rewriter); + if (i32Type != indexType) + builtinValue = rewriter.create(op.getLoc(), indexType, + builtinValue); + rewriter.replaceOp(op, builtinValue); return success(); } diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp --- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp +++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp @@ -85,7 +85,9 @@ std::unique_ptr target = SPIRVConversionTarget::get(targetAttr); - SPIRVTypeConverter typeConverter(targetAttr); + SPIRVConversionOptions options; + options.use64bitIndex = this->use64bitIndex; + SPIRVTypeConverter typeConverter(targetAttr, options); typeConverter.addConversion([&](gpu::MMAMatrixType type) -> Type { return convertMMAToSPIRVType(type); }); diff --git a/mlir/test/Conversion/GPUToSPIRV/builtins.mlir b/mlir/test/Conversion/GPUToSPIRV/builtins.mlir --- a/mlir/test/Conversion/GPUToSPIRV/builtins.mlir +++ b/mlir/test/Conversion/GPUToSPIRV/builtins.mlir @@ -1,6 +1,10 @@ -// RUN: mlir-opt -split-input-file -convert-gpu-to-spirv %s -o - | FileCheck %s +// RUN: mlir-opt -split-input-file -convert-gpu-to-spirv="use-64bit-index=false" %s -o - | FileCheck %s --check-prefix=INDEX32 +// RUN: mlir-opt -split-input-file -convert-gpu-to-spirv="use-64bit-index=true" %s -o - | FileCheck %s --check-prefix=INDEX64 -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_workgroup_id_x @@ -8,14 +12,17 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") : !spirv.ptr, Input> + // INDEX64-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX64: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_workgroup_id_x() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} + // INDEX64: spirv.UConvert %{{.+}} : i32 to i64 %0 = gpu.block_id x gpu.return } @@ -24,7 +31,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index %c256 = arith.constant 256 : i32 @@ -34,14 +44,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_workgroup_id_y() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}} %0 = gpu.block_id y gpu.return } @@ -50,7 +60,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_workgroup_id_z @@ -58,14 +71,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[WORKGROUPID:@.*]] built_in("WorkgroupId") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_workgroup_id_z() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPID]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}} %0 = gpu.block_id z gpu.return } @@ -74,7 +87,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_workgroup_size_x @@ -82,7 +98,7 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 gpu.module @kernels { gpu.func @builtin_workgroup_size_x() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { @@ -90,7 +106,7 @@ // Note that this ignores the workgroup size specification in gpu.launch. // We may want to define gpu.workgroup_size and convert it to the entry // point ABI we want here. - // CHECK: spirv.Constant 32 : i32 + // INDEX32: spirv.Constant 32 : i32 %0 = gpu.block_dim x gpu.return } @@ -99,7 +115,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_workgroup_size_y @@ -107,12 +126,12 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 gpu.module @kernels { gpu.func @builtin_workgroup_size_y() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { // The constant value is obtained from the spirv.entry_point_abi. - // CHECK: spirv.Constant 4 : i32 + // INDEX32: spirv.Constant 4 : i32 %0 = gpu.block_dim y gpu.return } @@ -121,7 +140,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_workgroup_size_z @@ -129,12 +151,12 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 gpu.module @kernels { gpu.func @builtin_workgroup_size_z() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { // The constant value is obtained from the spirv.entry_point_abi. - // CHECK: spirv.Constant 1 : i32 + // INDEX32: spirv.Constant 1 : i32 %0 = gpu.block_dim z gpu.return } @@ -143,7 +165,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_local_id_x @@ -151,14 +176,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[LOCALINVOCATIONID:@.*]] built_in("LocalInvocationId") + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[LOCALINVOCATIONID:@.*]] built_in("LocalInvocationId") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_local_id_x() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[LOCALINVOCATIONID]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[LOCALINVOCATIONID]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} %0 = gpu.thread_id x gpu.return } @@ -167,7 +192,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_num_workgroups_x @@ -175,14 +203,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[NUMWORKGROUPS:@.*]] built_in("NumWorkgroups") + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[NUMWORKGROUPS:@.*]] built_in("NumWorkgroups") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_num_workgroups_x() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[NUMWORKGROUPS]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[NUMWORKGROUPS]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} %0 = gpu.grid_dim x gpu.return } @@ -191,14 +219,17 @@ // ----- -module attributes {gpu.container_module} { - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[SUBGROUPID:@.*]] built_in("SubgroupId") +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[SUBGROUPID:@.*]] built_in("SubgroupId") : !spirv.ptr gpu.module @kernels { gpu.func @builtin_subgroup_id() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[SUBGROUPID]] - // CHECK-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]] + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[SUBGROUPID]] + // INDEX32-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]] %0 = gpu.subgroup_id : index gpu.return } @@ -207,14 +238,17 @@ // ----- -module attributes {gpu.container_module} { - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[NUMSUBGROUPS:@.*]] built_in("NumSubgroups") +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[NUMSUBGROUPS:@.*]] built_in("NumSubgroups") : !spirv.ptr gpu.module @kernels { gpu.func @builtin_num_subgroups() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[NUMSUBGROUPS]] - // CHECK-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]] + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[NUMSUBGROUPS]] + // INDEX32-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]] %0 = gpu.num_subgroups : index gpu.return } @@ -223,7 +257,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_workgroup_size_x @@ -231,14 +268,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} - // CHECK: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") + // INDEX32-LABEL: spirv.module @{{.*}} + // INDEX32: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_workgroup_size_x() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} %0 = gpu.block_dim x gpu.return } @@ -247,7 +284,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_workgroup_size_y @@ -255,14 +295,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} - // CHECK: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") + // INDEX32-LABEL: spirv.module @{{.*}} + // INDEX32: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_workgroup_size_y() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}} %0 = gpu.block_dim y gpu.return } @@ -271,7 +311,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_workgroup_size_z @@ -279,14 +322,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} - // CHECK: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") + // INDEX32-LABEL: spirv.module @{{.*}} + // INDEX32: spirv.GlobalVariable [[WORKGROUPSIZE:@.*]] built_in("WorkgroupSize") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_workgroup_size_z() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi<>} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[WORKGROUPSIZE]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}} %0 = gpu.block_dim z gpu.return } @@ -295,7 +338,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_global_id_x @@ -303,14 +349,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_global_id_x() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}} %0 = gpu.global_id x gpu.return } @@ -319,7 +365,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_global_id_y @@ -327,14 +376,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_global_id_y() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}} %0 = gpu.global_id y gpu.return } @@ -343,7 +392,10 @@ // ----- -module attributes {gpu.container_module} { +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { func.func @builtin() { %c0 = arith.constant 1 : index gpu.launch_func @kernels::@builtin_global_id_z @@ -351,14 +403,14 @@ return } - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId") : !spirv.ptr, Input> gpu.module @kernels { gpu.func @builtin_global_id_z() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]] - // CHECK-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] - // CHECK-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}} + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[GLOBALINVOCATIONID]] + // INDEX32-NEXT: [[VEC:%.*]] = spirv.Load "Input" [[ADDRESS]] + // INDEX32-NEXT: {{%.*}} = spirv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}} %0 = gpu.global_id z gpu.return } @@ -368,14 +420,20 @@ // ----- -module attributes {gpu.container_module} { - // CHECK-LABEL: spirv.module @{{.*}} Logical GLSL450 - // CHECK: spirv.GlobalVariable [[SUBGROUPSIZE:@.*]] built_in("SubgroupSize") +module attributes { + gpu.container_module, + spirv.target_env = #spirv.target_env<#spirv.vce, #spirv.resource_limits<>> +} { + // INDEX32-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX32: spirv.GlobalVariable [[SUBGROUPSIZE:@.*]] built_in("SubgroupSize") : !spirv.ptr + // INDEX64-LABEL: spirv.module @{{.*}} Logical GLSL450 + // INDEX64: spirv.GlobalVariable [[SUBGROUPSIZE:@.*]] built_in("SubgroupSize") : !spirv.ptr gpu.module @kernels { gpu.func @builtin_subgroup_size() kernel attributes {spirv.entry_point_abi = #spirv.entry_point_abi} { - // CHECK: [[ADDRESS:%.*]] = spirv.mlir.addressof [[SUBGROUPSIZE]] - // CHECK-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]] + // INDEX32: [[ADDRESS:%.*]] = spirv.mlir.addressof [[SUBGROUPSIZE]] + // INDEX32-NEXT: {{%.*}} = spirv.Load "Input" [[ADDRESS]] + // INDEX64: spirv.UConvert %{{.+}} : i32 to i64 %0 = gpu.subgroup_size : index gpu.return }