Debian Codegraph @

mlir/test/Dialect/Linalg/vectorization/pad.mlir

raw
1 // RUN: mlir-opt %s -transform-interpreter -split-input-file | FileCheck %s
2
3 ///----------------------------------------------------------------------------------------
4 /// Tests for tensor.pad
5 ///----------------------------------------------------------------------------------------
6
7 // CHECK-LABEL: func @test_masked_vectorize_pad
8 func.func @test_masked_vectorize_pad(
9 %0 : tensor<?x?xf32>, %h0 : index, %h1 : index)
10 -> tensor<2x4xf32>
11 {
12 // CHECK-DAG: %[[c42:.*]] = arith.constant 4.243000e+01 : f32
13 // CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index
14 // CHECK-DAG: %[[c0_0:.*]] = arith.constant 0 : index
15 // CHECK: %[[d0:.*]] = tensor.dim {{.*}} : tensor<?x?xf32>
16 // CHECK: %[[d1:.*]] = tensor.dim {{.*}} : tensor<?x?xf32>
17 // CHECK: %[[mask:.*]] = vector.create_mask %[[d0]], %[[d1]] : vector<2x4xi1>
18 // CHECK: %[[masked_read:.*]] = vector.mask %[[mask]] {
19 // CHECK-SAME: vector.transfer_read %{{.*}}[%[[c0_0]], %[[c0_0]]], %[[c42]]
20 // CHECK-SAME: {in_bounds = [true, true]} : tensor<?x?xf32>, vector<2x4xf32>
21 // CHECK-SAME: } : vector<2x4xi1> -> vector<2x4xf32>
22 // CHECK-DAG: %[[c0_1:.*]] = arith.constant 0 : index
23 // CHECK-DAG: %[[empty:.*]] = tensor.empty() : tensor<2x4xf32>
24 // CHECK: vector.transfer_write %[[masked_read]], %[[empty]][%[[c0_1]], %[[c0_1]]]
25 // CHECK-SAME: {in_bounds = [true, true]} : vector<2x4xf32>, tensor<2x4xf32>
26 %cst = arith.constant 42.43 : f32
27 %c0 = arith.constant 0 : index
28 %1 = tensor.pad %0 low[0, %c0] high[%h0, %h1] {
29 ^bb0(%hh1: index, %hh2: index):
30 tensor.yield %cst : f32
31 } : tensor<?x?xf32> to tensor<2x4xf32>
32 return %1: tensor<2x4xf32>
33 }
34
35 module attributes {transform.with_named_sequence} {
36 transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
37 %0 = transform.structured.match ops{["tensor.pad"]} in %arg1
38 : (!transform.any_op) -> !transform.any_op
39 transform.structured.vectorize %0 vector_sizes [2, 4] : !transform.any_op
40 transform.yield
41 }
42 }
43
44 // -----
45
46 // CHECK: #[[MAP:.+]] = affine_map<()[s0, s1] -> (s0 + s1)>
47 // CHECK: func @test_masked_vectorize_dynamic_pad
48 func.func @test_masked_vectorize_dynamic_pad(
49 %0 : tensor<?x?xf32>, %h0 : index, %h1 : index)
50 -> tensor<?x?xf32>
51 {
52 // CHECK-DAG: %[[c42:.*]] = arith.constant 4.243000e+01 : f32
53 // CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index
54 // CHECK-DAG: %[[res_d0:.+]] = affine.apply #[[MAP]]()
55 // CHECK-DAG: %[[res_d1:.+]] = affine.apply #[[MAP]]()
56 // CHECK: %[[c0_2:.*]] = arith.constant 0 : index
57 // CHECK: %[[d0:.*]] = tensor.dim {{.*}} : tensor<?x?xf32>
58 // CHECK: %[[d1:.*]] = tensor.dim {{.*}} : tensor<?x?xf32>
59 // CHECK: %[[mask:.*]] = vector.create_mask %[[d0]], %[[d1]] : vector<2x4xi1>
60 // CHECK: %[[masked_read:.*]] = vector.mask %[[mask]] {
61 // CHECK-SAME: vector.transfer_read %{{.*}}[%[[c0_2]], %[[c0_2]]], %[[c42]]
62 // CHECK-SAME: {in_bounds = [true, true]} : tensor<?x?xf32>, vector<2x4xf32>
63 // CHECK-SAME: } : vector<2x4xi1> -> vector<2x4xf32>
64 // CHECK-DAG: %[[empty:.*]] = tensor.empty(%[[res_d0]], %[[res_d1]]) : tensor<?x?xf32>
65 // CHECK-DAG: %[[c0_3:.*]] = arith.constant 0 : index
66 // CHECK-DAG: %[[d2:.*]] = tensor.dim %[[empty]], {{.*}} : tensor<?x?xf32>
67 // CHECK-DAG: %[[d3:.*]] = tensor.dim %[[empty]], {{.*}} : tensor<?x?xf32>
68 // CHECK: %[[mask_2:.*]] = vector.create_mask %[[d2]], %[[d3]] : vector<2x4xi1>
69 // CHECK: %[[masked_write:.*]] = vector.mask %[[mask_2]] {
70 // CHECK-SAME: vector.transfer_write %[[masked_read]], %[[empty]][%[[c0_3]], %[[c0_3]]]
71 // CHECK-SAME: {in_bounds = [true, true]} : vector<2x4xf32>, tensor<?x?xf32>
72 // CHECK: return %[[masked_write]] : tensor<?x?xf32>
73 %cst = arith.constant 42.43 : f32
74 %c0 = arith.constant 0 : index
75 %1 = tensor.pad %0 low[0, %c0] high[%h0, %h1] {
76 ^bb0(%hh1: index, %hh2: index):
77 tensor.yield %cst : f32
78 } : tensor<?x?xf32> to tensor<?x?xf32>
79 return %1: tensor<?x?xf32>
80 }
81
82 module attributes {transform.with_named_sequence} {
83 transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
84 %0 = transform.structured.match ops{["tensor.pad"]} in %arg1
85 : (!transform.any_op) -> !transform.any_op
86 transform.structured.vectorize %0 vector_sizes [2, 4] : !transform.any_op
87 transform.yield
88 }
89 }
90
91 // -----
92 // This case is supported because low padding `%l0` is applied on
93 // a unit dimension which is supported, non unit result dimension low
94 // padding is currently unsupported.
95 // CHECK-LABEL: func @test_masked_vectorize_non_zero_low_pad_unit_res_dim
96 func.func @test_masked_vectorize_non_zero_low_pad_unit_res_dim(
97 %0 : tensor<?x?xf32>, %h0 : index, %h1 : index, %l0 : index)
98 -> tensor<1x4xf32>
99 {
100 // CHECK-DAG: %[[C42:.*]] = arith.constant 4.243000e+01 : f32
101 // CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index
102 // CHECK: %[[C0_1:.*]] = arith.constant 0 : index
103 // CHECK-DAG: %[[D0:.*]] = tensor.dim {{.*}} : tensor<?x?xf32>
104 // CHECK-DAG: %[[D1:.*]] = tensor.dim {{.*}} : tensor<?x?xf32>
105 // CHECK: %[[MASK:.*]] = vector.create_mask %[[D0]], %[[D1]] : vector<1x4xi1>
106 // CHECK: %[[MASKED_READ:.*]] = vector.mask %[[MASK]] {
107 // CHECK-SAME: vector.transfer_read %{{.*}}[%[[C0_1]], %[[C0_1]]], %[[C42]]
108 // CHECK-SAME: {in_bounds = [true, true]} : tensor<?x?xf32>, vector<1x4xf32>
109 // CHECK-SAME: } : vector<1x4xi1> -> vector<1x4xf32>
110 // CHECK-DAG: %[[EMPTY:.*]] = tensor.empty() : tensor<1x4xf32>
111 // CHECK-DAG: %[[C0_2:.*]] = arith.constant 0 : index
112 // CHECK: %[[MASKED_WRITE:.*]] = vector.transfer_write %[[MASKED_READ]], %[[EMPTY]][%[[C0_2]], %[[C0_2]]]
113 // CHECK-SAME: {in_bounds = [true, true]} : vector<1x4xf32>, tensor<1x4xf32>
114 // CHECK: return %[[MASKED_WRITE]] : tensor<1x4xf32>
115 %cst = arith.constant 42.43 : f32
116 %c0 = arith.constant 0 : index
117 %1 = tensor.pad %0 low[%l0, %c0] high[%h0, %h1] {
118 ^bb0(%hh1: index, %hh2: index):
119 tensor.yield %cst : f32
120 } : tensor<?x?xf32> to tensor<1x4xf32>
121 return %1: tensor<1x4xf32>
122 }
123
124 module attributes {transform.with_named_sequence} {
125 transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
126 %0 = transform.structured.match ops{["tensor.pad"]} in %arg1
127 : (!transform.any_op) -> !transform.any_op
128 transform.structured.vectorize %0 vector_sizes [1, 4] : !transform.any_op
129 transform.yield
130 }
131 }