|
| 1 | +// RUN: mlir-opt -split-input-file -convert-gpu-to-spirv -verify-diagnostics %s -o - | FileCheck %s |
| 2 | + |
| 3 | +module attributes { |
| 4 | + gpu.container_module, |
| 5 | + spirv.target_env = #spirv.target_env<#spirv.vce<v1.4, [Shader, GroupNonUniformRotateKHR], []>, |
| 6 | + #spirv.resource_limits<subgroup_size = 16>> |
| 7 | +} { |
| 8 | + |
| 9 | +gpu.module @kernels { |
| 10 | + // CHECK-LABEL: spirv.func @rotate() |
| 11 | + gpu.func @rotate() kernel |
| 12 | + attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} { |
| 13 | + %offset = arith.constant 4 : i32 |
| 14 | + %width = arith.constant 16 : i32 |
| 15 | + %val = arith.constant 42.0 : f32 |
| 16 | + |
| 17 | + // CHECK: %[[OFFSET:.+]] = spirv.Constant 4 : i32 |
| 18 | + // CHECK: %[[WIDTH:.+]] = spirv.Constant 16 : i32 |
| 19 | + // CHECK: %[[VAL:.+]] = spirv.Constant 4.200000e+01 : f32 |
| 20 | + // CHECK: %{{.+}} = spirv.GroupNonUniformRotateKHR <Subgroup> %[[VAL]], %[[OFFSET]], cluster_size(%[[WIDTH]]) : f32, i32, i32 -> f32 |
| 21 | + // CHECK: %{{.+}} = spirv.Constant true |
| 22 | + %result, %valid = gpu.rotate %val, %offset, %width : f32 |
| 23 | + gpu.return |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +} |
| 28 | + |
| 29 | +// ----- |
| 30 | + |
| 31 | +module attributes { |
| 32 | + gpu.container_module, |
| 33 | + spirv.target_env = #spirv.target_env<#spirv.vce<v1.4, [Shader, GroupNonUniformRotateKHR], []>, |
| 34 | + #spirv.resource_limits<subgroup_size = 16>> |
| 35 | +} { |
| 36 | + |
| 37 | +gpu.module @kernels { |
| 38 | + // CHECK-LABEL: spirv.func @rotate_width_less_than_subgroup_size() |
| 39 | + gpu.func @rotate_width_less_than_subgroup_size() kernel |
| 40 | + attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} { |
| 41 | + %offset = arith.constant 4 : i32 |
| 42 | + %width = arith.constant 8 : i32 |
| 43 | + %val = arith.constant 42.0 : f32 |
| 44 | + |
| 45 | + // CHECK: %[[OFFSET:.+]] = spirv.Constant 4 : i32 |
| 46 | + // CHECK: %[[WIDTH:.+]] = spirv.Constant 8 : i32 |
| 47 | + // CHECK: %[[VAL:.+]] = spirv.Constant 4.200000e+01 : f32 |
| 48 | + // CHECK: %{{.+}} = spirv.GroupNonUniformRotateKHR <Subgroup> %[[VAL]], %[[OFFSET]], cluster_size(%[[WIDTH]]) : f32, i32, i32 -> f32 |
| 49 | + // CHECK: %[[INVOCATION_ID_ADDR:.+]] = spirv.mlir.addressof @__builtin__SubgroupLocalInvocationId__ |
| 50 | + // CHECK: %[[INVOCATION_ID:.+]] = spirv.Load "Input" %[[INVOCATION_ID_ADDR]] |
| 51 | + // CHECK: %{{.+}} = spirv.ULessThan %[[INVOCATION_ID]], %[[WIDTH]] |
| 52 | + %result, %valid = gpu.rotate %val, %offset, %width : f32 |
| 53 | + gpu.return |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +} |
| 58 | + |
| 59 | +// ----- |
| 60 | + |
| 61 | +module attributes { |
| 62 | + gpu.container_module, |
| 63 | + spirv.target_env = #spirv.target_env<#spirv.vce<v1.4, [Shader, GroupNonUniformRotateKHR], []>, |
| 64 | + #spirv.resource_limits<subgroup_size = 16>> |
| 65 | +} { |
| 66 | + |
| 67 | +gpu.module @kernels { |
| 68 | + gpu.func @rotate_with_bigger_than_subgroup_size() kernel |
| 69 | + attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} { |
| 70 | + %offset = arith.constant 4 : i32 |
| 71 | + %width = arith.constant 32 : i32 |
| 72 | + %val = arith.constant 42.0 : f32 |
| 73 | + |
| 74 | + // expected-error @+1 {{failed to legalize operation 'gpu.rotate'}} |
| 75 | + %result, %valid = gpu.rotate %val, %offset, %width : f32 |
| 76 | + gpu.return |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +} |
| 81 | + |
| 82 | +// ----- |
| 83 | + |
| 84 | +module attributes { |
| 85 | + gpu.container_module, |
| 86 | + spirv.target_env = #spirv.target_env<#spirv.vce<v1.4, [Shader, GroupNonUniformRotateKHR], []>, |
| 87 | + #spirv.resource_limits<subgroup_size = 16>> |
| 88 | +} { |
| 89 | + |
| 90 | +gpu.module @kernels { |
| 91 | + gpu.func @rotate_non_const_width(%width: i32) kernel |
| 92 | + attributes {spirv.entry_point_abi = #spirv.entry_point_abi<workgroup_size = [16, 1, 1]>} { |
| 93 | + %offset = arith.constant 4 : i32 |
| 94 | + %val = arith.constant 42.0 : f32 |
| 95 | + |
| 96 | + // expected-error @+1 {{'gpu.rotate' op width is not a constant value}} |
| 97 | + %result, %valid = gpu.rotate %val, %offset, %width : f32 |
| 98 | + gpu.return |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +} |
0 commit comments