// RUN: mlir-opt -transform-interpreter %s --split-input-file --allow-unregistered-dialect | FileCheck %s // CHECK-LABEL: func @insert_slice_to_copy // CHECK-SAME: %[[I:.*]]: tensor<2x3xf32> // CHECK-SAME: %[[O:.*]]: tensor, // CHECK-SAME: %[[OFF0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[OFF1:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[SZ0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[SZ1:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[ST0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[ST1:[0-9a-zA-Z]+]]: index) func.func @insert_slice_to_copy( %I : tensor<2x3xf32>, %O : tensor, %off0 : index, %off1 : index, %sz0 : index, %sz1 : index, %st0 : index, %st1 : index) -> tensor { // CHECK: %[[EXTRACTED_SLICE:.*]] = tensor.extract_slice %[[O]][%[[OFF0]], %[[OFF1]]] [2, 3] [%[[ST0]], %[[ST1]]] // CHECK-SAME: : tensor to tensor<2x3xf32> // CHECK: linalg.copy ins(%[[I]] : tensor<2x3xf32>) outs(%[[EXTRACTED_SLICE]] : tensor<2x3xf32>) -> tensor<2x3xf32> // CHECK: tensor.insert_slice %{{.*}} into %[[O]][%[[OFF0]], %[[OFF1]]] [2, 3] [%[[ST0]], %[[ST1]]] // CHECK-SAME: : tensor<2x3xf32> into tensor %0 = tensor.insert_slice %I into %O[%off0, %off1] [2, 3] [%st0, %st1] : tensor<2x3xf32> into tensor return %0 : tensor } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { %0 = transform.structured.match ops{["tensor.insert_slice"]} in %arg1 : (!transform.any_op) -> !transform.any_op %1 = transform.structured.insert_slice_to_copy %0 : (!transform.any_op) -> !transform.any_op transform.cast %1 : !transform.any_op to !transform.op<"linalg.copy"> transform.yield } } // ----- // CHECK-LABEL: func @insert_slice_to_copy // CHECK-SAME: %[[I:[0-9a-zA-Z]+]]: tensor // CHECK-SAME: %[[O:[0-9a-zA-Z]+]]: tensor, // CHECK-SAME: %[[OFF0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[OFF1:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[SZ0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[SZ1:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[ST0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[ST1:[0-9a-zA-Z]+]]: index) func.func @insert_slice_to_copy( %I : tensor, %O : tensor, %off0 : index, %off1 : index, %sz0 : index, %sz1 : index, %st0 : index, %st1 : index) -> tensor { // CHECK: %[[EXTRACTED_SLICE:.*]] = tensor.extract_slice %[[O]][%[[OFF0]], %[[OFF1]]] [%[[SZ0]], %[[SZ1]]] [1, 1] // CHECK-SAME: : tensor to tensor // CHECK: linalg.copy ins(%[[I]] : tensor) outs(%[[EXTRACTED_SLICE]] : tensor) -> tensor // CHECK: tensor.insert_slice %{{.*}} into %[[O]][%[[OFF0]], %[[OFF1]]] [%[[SZ0]], %[[SZ1]]] [1, 1] // CHECK-SAME: : tensor into tensor %0 = tensor.insert_slice %I into %O[%off0, %off1] [%sz0, %sz1] [1, 1] : tensor into tensor return %0 : tensor } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { %0 = transform.structured.match ops{["tensor.insert_slice"]} in %arg1 : (!transform.any_op) -> !transform.any_op %1 = transform.structured.insert_slice_to_copy %0 : (!transform.any_op) -> !transform.any_op transform.cast %1 : !transform.any_op to !transform.op<"linalg.copy"> transform.yield } } // ----- // CHECK-LABEL: func @insert_slice_to_copy // CHECK-SAME: %[[I:.*]]: tensor<2x3xf32> // CHECK-SAME: %[[O:.*]]: tensor, // CHECK-SAME: %[[OFF0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[OFF1:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[SZ0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[SZ1:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[ST0:[0-9a-zA-Z]+]]: index, // CHECK-SAME: %[[ST1:[0-9a-zA-Z]+]]: index) func.func @insert_slice_to_copy( %I : tensor<2x3xf32>, %O : tensor, %off0 : index, %off1 : index, %sz0 : index, %sz1 : index, %st0 : index, %st1 : index) -> tensor { // CHECK: %[[EXTRACTED_SLICE:.*]] = tensor.extract_slice %[[O]][%[[OFF0]], %[[OFF1]]] [2, 3] [%[[ST0]], %[[ST1]]] // CHECK-SAME: : tensor to tensor<2x3xf32> // CHECK: linalg.copy ins(%[[I]] : tensor<2x3xf32>) outs(%[[EXTRACTED_SLICE]] : tensor<2x3xf32>) -> tensor<2x3xf32> // CHECK-NOT: linalg.copy // CHECK: tensor.insert_slice %{{.*}} into %[[O]][%[[OFF0]], %[[OFF1]]] [2, 3] [%[[ST0]], %[[ST1]]] // CHECK-SAME: : tensor<2x3xf32> into tensor %extracted_slice = tensor.extract_slice %O[%off0, %off1] [2, 3] [%st0, %st1] : tensor to tensor<2x3xf32> %0 = linalg.copy ins(%I : tensor<2x3xf32>) outs(%extracted_slice : tensor<2x3xf32>) -> tensor<2x3xf32> %inserted_slice = tensor.insert_slice %0 into %O[%off0, %off1] [2, 3] [%st0, %st1] : tensor<2x3xf32> into tensor return %inserted_slice : tensor } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { %0 = transform.structured.match ops{["tensor.insert_slice"]} in %arg1 : (!transform.any_op) -> !transform.any_op %1 = transform.structured.insert_slice_to_copy %0 : (!transform.any_op) -> !transform.any_op transform.cast %1 : !transform.any_op to !transform.op<"linalg.copy"> transform.yield } } // ----- // CHECK-LABEL: func @parallel_insert_slice_to_copy func.func @parallel_insert_slice_to_copy(%out : tensor, %sz0: index, %sz1: index) { %0 = scf.forall (%arg0, %arg1) in (27, 8) shared_outs(%arg2 = %out) -> (tensor) { %t = "make_me_a_tensor"() : () -> (tensor ) // CHECK: tensor.extract_slice // CHECK: linalg.copy // CHECK: scf.forall.in_parallel // CHECK: tensor.parallel_insert_slice scf.forall.in_parallel { tensor.parallel_insert_slice %t into %arg2[0, 0] [%sz0, %sz1] [1, 1] : tensor into tensor } } return } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { %0 = transform.structured.match ops{["tensor.parallel_insert_slice"]} in %arg1 : (!transform.any_op) -> !transform.any_op %1 = transform.structured.insert_slice_to_copy %0 : (!transform.any_op) -> !transform.any_op transform.cast %1 : !transform.any_op to !transform.op<"linalg.copy"> transform.yield } }