@@ -1935,17 +1935,80 @@ module attributes {transform.with_named_sequence} {
1935
1935
/// tensor.insert_slice
1936
1936
///----------------------------------------------------------------------------------------
1937
1937
1938
- // CHECK-LABEL: func @insert_slice
1938
+ // The pad value for xfer-read is neither needed nor available - use the default (0.0).
1939
+
1940
+ // CHECK-LABEL: func @insert_static_slice_default_pad
1939
1941
// CHECK-SAME: %[[ARG_0:.*]]: tensor<1x2x3xf32>,
1940
1942
// CHECK-SAME: %[[ARG_1:.*]]: tensor<9x8x7x1x2x3xf32>) -> tensor<9x8x7x1x2x3xf32> {
1941
1943
// CHECK: %[[PAD:.*]] = arith.constant 0.000000e+00 : f32
1942
1944
// CHECK: %[[C0:.*]] = arith.constant 0 : index
1943
1945
// CHECK: %[[READ:.*]] = vector.transfer_read %[[ARG_0]]{{\[}}%[[C0]], %[[C0]], %[[C0]]], %[[PAD]] {in_bounds = [true, true, true]} : tensor<1x2x3xf32>, vector<1x2x3xf32>
1944
1946
// CHECK: %[[WRITE:.*]] = vector.transfer_write %[[READ]], %[[ARG_1]]{{\[}}%[[C0]], %[[C0]], %[[C0]], %[[C0]], %[[C0]], %[[C0]]] {in_bounds = [true, true, true]} : vector<1x2x3xf32>, tensor<9x8x7x1x2x3xf32>
1945
1947
// CHECK: return %[[WRITE]] : tensor<9x8x7x1x2x3xf32>
1946
- func.func @insert_slice (%arg0: tensor <1 x2 x3 xf32 >, %arg1: tensor <9 x8 x7 x1 x2 x3 xf32 >) -> tensor <9 x8 x7 x1 x2 x3 xf32 > {
1947
- %0 = tensor.insert_slice %arg0 into %arg1 [0 , 0 , 0 , 0 , 0 , 0 ] [1 , 1 , 1 , 1 , 2 , 3 ][1 , 1 , 1 , 1 , 1 , 1 ] : tensor <1 x2 x3 xf32 > into tensor <9 x8 x7 x1 x2 x3 xf32 >
1948
- return %0 : tensor <9 x8 x7 x1 x2 x3 xf32 >
1948
+ func.func @insert_static_slice_default_pad (%arg0: tensor <1 x2 x3 xf32 >, %arg1: tensor <9 x8 x7 x1 x2 x3 xf32 >) -> tensor <9 x8 x7 x1 x2 x3 xf32 > {
1949
+ %res = tensor.insert_slice %arg0 into %arg1 [0 , 0 , 0 , 0 , 0 , 0 ] [1 , 1 , 1 , 1 , 2 , 3 ][1 , 1 , 1 , 1 , 1 , 1 ] : tensor <1 x2 x3 xf32 > into tensor <9 x8 x7 x1 x2 x3 xf32 >
1950
+ return %res : tensor <9 x8 x7 x1 x2 x3 xf32 >
1951
+ }
1952
+
1953
+ module attributes {transform.with_named_sequence } {
1954
+ transform.named_sequence @__transform_main (%arg1: !transform.any_op {transform.readonly }) {
1955
+ %0 = transform.structured.match ops {[" tensor.insert_slice" ]} in %arg1 : (!transform.any_op ) -> !transform.any_op
1956
+ %1 = transform.get_parent_op %0 {isolated_from_above } : (!transform.any_op ) -> !transform.any_op
1957
+ %2 = transform.structured.vectorize_children_and_apply_patterns %1 { vectorize_padding } : (!transform.any_op ) -> !transform.any_op
1958
+ transform.yield
1959
+ }
1960
+ }
1961
+
1962
+ // -----
1963
+
1964
+ // Same as above, but there's a pad value available that should be used instead of the default value.
1965
+
1966
+ // CHECK-LABEL: func.func @insert_static_slice_non_zero_pad
1967
+ // CHECK-SAME: %[[ARG_0:.*]]: tensor<1x2x3xf32>,
1968
+ // CHECK-SAME: %[[PAD:.*]]: f32) -> tensor<9x8x7x1x2x3xf32> {
1969
+ // CHECK: %[[EMPTY:.*]] = tensor.empty() : tensor<9x8x7x1x2x3xf32>
1970
+ // CHECK: %[[BC:.*]] = vector.broadcast %[[PAD]] : f32 to vector<9x8x7x1x2x3xf32>
1971
+ // CHECK: %[[WRITE:.*]] = vector.transfer_write %[[BC]], %[[EMPTY]]{{.*}} {in_bounds = [true, true, true, true, true, true]} : vector<9x8x7x1x2x3xf32>, tensor<9x8x7x1x2x3xf32>
1972
+ // CHECK: %[[READ:.*]] = vector.transfer_read %[[ARG_0]]{{.*}}, %[[PAD]] {in_bounds = [true, true, true]} : tensor<1x2x3xf32>, vector<1x2x3xf32>
1973
+ // CHECK: %[[RES:.*]] = vector.transfer_write %[[READ]], %[[WRITE]]{{.*}} {in_bounds = [true, true, true]} : vector<1x2x3xf32>, tensor<9x8x7x1x2x3xf32>
1974
+ // CHECK: return %[[RES]] : tensor<9x8x7x1x2x3xf32>
1975
+ func.func @insert_static_slice_non_zero_pad (%arg0: tensor <1 x2 x3 xf32 >, %pad : f32 ) -> tensor <9 x8 x7 x1 x2 x3 xf32 > {
1976
+ %init = tensor.empty () : tensor <9 x8 x7 x1 x2 x3 xf32 >
1977
+ %fill = linalg.fill ins (%pad : f32 ) outs (%init : tensor <9 x8 x7 x1 x2 x3 xf32 >) -> tensor <9 x8 x7 x1 x2 x3 xf32 >
1978
+ %res = tensor.insert_slice %arg0 into %fill [0 , 0 , 0 , 0 , 0 , 0 ] [1 , 1 , 1 , 1 , 2 , 3 ][1 , 1 , 1 , 1 , 1 , 1 ] : tensor <1 x2 x3 xf32 > into tensor <9 x8 x7 x1 x2 x3 xf32 >
1979
+ return %res : tensor <9 x8 x7 x1 x2 x3 xf32 >
1980
+ }
1981
+
1982
+ module attributes {transform.with_named_sequence } {
1983
+ transform.named_sequence @__transform_main (%arg1: !transform.any_op {transform.readonly }) {
1984
+ %0 = transform.structured.match ops {[" tensor.insert_slice" ]} in %arg1 : (!transform.any_op ) -> !transform.any_op
1985
+ %1 = transform.get_parent_op %0 {isolated_from_above } : (!transform.any_op ) -> !transform.any_op
1986
+ %2 = transform.structured.vectorize_children_and_apply_patterns %1 { vectorize_padding } : (!transform.any_op ) -> !transform.any_op
1987
+ transform.yield
1988
+ }
1989
+ }
1990
+
1991
+ // -----
1992
+
1993
+ // Same as above, but the source type has is dynamically shaped. This means
1994
+ // that the pad value is now required and the vector dim corresponding to the
1995
+ // dynamic shape has to be inferred from the shape of the destination tensor.
1996
+
1997
+ // CHECK-LABEL: func.func @insert_dynamic_slice_non_zero_pad(
1998
+ // CHECK-SAME: %[[ARG_0:.*]]: tensor<1x?x3xf32>,
1999
+ // CHECK-SAME: %[[PAD:.*]]: f32,
2000
+ // CHECK-SAME: %[[SIZE:.*]]: index) -> tensor<9x8x7x1x2x3xf32> {
2001
+ // CHECK: %[[EMPTY:.*]] = tensor.empty() : tensor<9x8x7x1x2x3xf32>
2002
+ // CHECK: %[[BC:.*]] = vector.broadcast %[[PAD]] : f32 to vector<9x8x7x1x2x3xf32>
2003
+ // CHECK: %[[WRITE:.*]] = vector.transfer_write %[[BC]], %[[EMPTY]]{{.*}} {in_bounds = [true, true, true, true, true, true]} : vector<9x8x7x1x2x3xf32>, tensor<9x8x7x1x2x3xf32>
2004
+ // CHECK: %[[READ:.*]] = vector.transfer_read %[[ARG_0]]{{.*}}, %[[PAD]] {in_bounds = [true, false, true]} : tensor<1x?x3xf32>, vector<1x2x3xf32>
2005
+ // CHECK: %[[RES:.*]] = vector.transfer_write %[[READ]], %[[WRITE]]{{.*}} {in_bounds = [true, true, true]} : vector<1x2x3xf32>, tensor<9x8x7x1x2x3xf32>
2006
+ // CHECK: return %[[RES]] : tensor<9x8x7x1x2x3xf32>
2007
+ func.func @insert_dynamic_slice_non_zero_pad (%arg0: tensor <1 x?x3 xf32 >, %pad : f32 , %size: index ) -> tensor <9 x8 x7 x1 x2 x3 xf32 > {
2008
+ %init = tensor.empty () : tensor <9 x8 x7 x1 x2 x3 xf32 >
2009
+ %fill = linalg.fill ins (%pad : f32 ) outs (%init : tensor <9 x8 x7 x1 x2 x3 xf32 >) -> tensor <9 x8 x7 x1 x2 x3 xf32 >
2010
+ %res = tensor.insert_slice %arg0 into %fill [0 , 0 , 0 , 0 , 0 , 0 ] [1 , 1 , 1 , 1 , %size , 3 ][1 , 1 , 1 , 1 , 1 , 1 ] : tensor <1 x?x3 xf32 > into tensor <9 x8 x7 x1 x2 x3 xf32 >
2011
+ return %res : tensor <9 x8 x7 x1 x2 x3 xf32 >
1949
2012
}
1950
2013
1951
2014
module attributes {transform.with_named_sequence } {
0 commit comments