// RUN: mlir-opt --transform-interpreter --split-input-file --verify-diagnostics %s | FileCheck %s #map = affine_map<(d0, d1, d2) -> (d0, d2)> #map1 = affine_map<(d0, d1, d2) -> (d2, d1)> #map2 = affine_map<(d0, d1, d2) -> (d0, d1)> func.func @specialize_matmul(%arg0: tensor, %arg1: tensor, %arg2: tensor) -> tensor { %0 = linalg.generic {indexing_maps = [#map, #map1, #map2], iterator_types = ["parallel", "parallel", "reduction"]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%in: f32, %in_0: f32, %out: f32): %0 = arith.mulf %in, %in_0 : f32 %1 = arith.addf %out, %0 : f32 linalg.yield %1 : f32 } -> tensor return %0 : tensor } // CHECK-LABEL: @specialize_matmul // CHECK-SAME: %[[ARG0:.+]]: tensor, %[[ARG1:.+]]: tensor, %[[ARG2:.+]]: tensor) -> tensor // CHECK-NOT: linalg.generic // CHECK: linalg.matmul ins(%[[ARG0]], %[[ARG1]] : tensor, tensor) outs(%[[ARG2]] : tensor) -> tensor module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { %0 = transform.structured.match interface{LinalgOp} in %arg0 : (!transform.any_op) -> !transform.any_op %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op transform.yield } } // ----- #map = affine_map<(d0, d1, d2, d3) -> (d0, d1, d3)> #map1 = affine_map<(d0, d1, d2, d3) -> (d0, d3, d2)> #map2 = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2)> func.func @batch_matmul(%arg0: tensor<2x16x8xf32>, %arg1: tensor<2x8x16xf32>, %arg2: tensor<2x16x16xf32>) -> tensor<2x16x16xf32> { %0 = linalg.generic {indexing_maps = [#map, #map1, #map2], iterator_types = ["parallel", "parallel", "parallel", "reduction"]} ins(%arg0, %arg1 : tensor<2x16x8xf32>, tensor<2x8x16xf32>) outs(%arg2 : tensor<2x16x16xf32>) { ^bb0(%in: f32, %in_0: f32, %out: f32): %1 = arith.mulf %in, %in_0 : f32 %2 = arith.addf %out, %1 : f32 linalg.yield %2 : f32 } -> tensor<2x16x16xf32> return %0 : tensor<2x16x16xf32> } // CHECK-LABEL: @batch_matmul // CHECK-SAME: %[[ARG0:.+]]: tensor<2x16x8xf32>, %[[ARG1:.+]]: tensor<2x8x16xf32>, %[[ARG2:.+]]: tensor<2x16x16xf32>) -> tensor<2x16x16xf32> // CHECK-NOT: linalg.generic // CHECK: linalg.batch_matmul ins(%[[ARG0]], %[[ARG1]] : tensor<2x16x8xf32>, tensor<2x8x16xf32>) outs(%[[ARG2]] : tensor<2x16x16xf32>) -> tensor<2x16x16xf32> module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { %0 = transform.structured.match interface{LinalgOp} in %arg0 : (!transform.any_op) -> !transform.any_op %1 = transform.structured.specialize %0 : (!transform.any_op) -> !transform.any_op transform.yield } } // ----- #map = affine_map<(d0, d1, d2) -> (d0, d2)> #map1 = affine_map<(d0, d1, d2) -> (d2, d1)> #map2 = affine_map<(d0, d1, d2) -> (d0, d1)> func.func @category_contract(%arg0: tensor, %arg1: tensor, %arg2: tensor) -> tensor { %0 = linalg.generic {indexing_maps = [#map, #map1, #map2], iterator_types = ["parallel", "parallel", "reduction"]} ins(%arg0, %arg1 : tensor, tensor) outs(%arg2 : tensor) { ^bb0(%in: f32, %in_0: f32, %out: f32): %0 = arith.mulf %in, %in_0 : f32 %1 = arith.addf %out, %0 : f32 linalg.yield %1 : f32 } -> tensor return %0 : tensor } // CHECK-DAG: #[[$MAP_A:.+]] = affine_map<(d0, d1, d2) -> (d0, d2)> // CHECK-DAG: #[[$MAP_B:.+]] = affine_map<(d0, d1, d2) -> (d2, d1)> // CHECK-DAG: #[[$MAP_C:.+]] = affine_map<(d0, d1, d2) -> (d0, d1)> // CHECK-LABEL: @category_contract // CHECK-SAME: %[[ARG0:.+]]: tensor, %[[ARG1:.+]]: tensor, %[[ARG2:.+]]: tensor) -> tensor // CHECK-NOT: linalg.generic // CHECK: linalg.contract // CHECK-SAME: indexing_maps = {{\[}}#[[$MAP_A]], #[[$MAP_B]], #[[$MAP_C]]{{\]}} // CHECK-SAME: ins(%[[ARG0]], %[[ARG1]] : tensor, tensor) // CHECK-SAME: outs(%[[ARG2]] : tensor) -> tensor module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { %0 = transform.structured.match interface{LinalgOp} in %arg0 : (!transform.any_op) -> !transform.any_op %1 = transform.structured.specialize %0 {emit_category = true} : (!transform.any_op) -> !transform.any_op transform.yield } }