|
| 1 | +// RUN: mlir-opt %s -test-transform-dialect-interpreter -test-transform-dialect-erase-schedule -one-shot-bufferize -func-bufferize -lower-vector-mask --test-lower-to-llvm | \ |
| 2 | +// RUN: mlir-cpu-runner -e main -entry-point-result=void --shared-libs=%mlir_c_runner_utils,%mlir_runner_utils | \ |
| 3 | +// RUN: FileCheck %s |
| 4 | + |
| 5 | +func.func private @printMemrefF32(%ptr : tensor<*xf32>) |
| 6 | + |
| 7 | +func.func @main() { |
| 8 | + %c4 = arith.constant 4 : index |
| 9 | + %c8 = arith.constant 8 : index |
| 10 | + |
| 11 | + %A = arith.constant dense<[ |
| 12 | + [ 1.1, 2.1 ], |
| 13 | + [ 1.2, 2.2 ], |
| 14 | + [ 1.3, 2.3 ], |
| 15 | + [ 1.4, 2.4 ], |
| 16 | + [ 1.5, 2.5 ], |
| 17 | + [ 1.6, 2.6 ], |
| 18 | + [ 1.7, 2.7 ], |
| 19 | + [ 1.8, 2.8 ] |
| 20 | + ]> : tensor<8x2xf32> |
| 21 | + %B = arith.constant dense<[ |
| 22 | + [ 10.1, 11.1, 12.1, 13.1 ], |
| 23 | + [ 10.2, 11.2, 12.2, 13.2 ] |
| 24 | + ]> : tensor<2x4xf32> |
| 25 | + %C_dyn = bufferization.alloc_tensor(%c8, %c4) : tensor<?x?xf32> |
| 26 | + |
| 27 | + %A_dyn = tensor.cast %A : tensor<8x2xf32> to tensor<?x?xf32> |
| 28 | + %B_dyn = tensor.cast %B : tensor<2x4xf32> to tensor<?x?xf32> |
| 29 | + |
| 30 | + %c0_i32 = arith.constant 0 : i32 |
| 31 | + %C_init = linalg.fill ins(%c0_i32 : i32) outs(%C_dyn : tensor<?x?xf32>) -> tensor<?x?xf32> |
| 32 | + |
| 33 | + %res = linalg.matmul ins(%A_dyn, %B_dyn: tensor<?x?xf32>, tensor<?x?xf32>) |
| 34 | + outs(%C_init: tensor<?x?xf32>) -> tensor<?x?xf32> |
| 35 | + %xf = tensor.cast %res : tensor<?x?xf32> to tensor<*xf32> |
| 36 | + |
| 37 | + // CHECK: {{\[}}[32.53, 35.73, 38.93, 42.13], |
| 38 | + // CHECK-NEXT: [34.56, 37.96, 41.36, 44.76], |
| 39 | + // CHECK-NEXT: [36.59, 40.19, 43.79, 47.39], |
| 40 | + // CHECK-NEXT: [38.62, 42.42, 46.22, 50.02], |
| 41 | + // CHECK-NEXT: [0, 0, 0, 0], |
| 42 | + // CHECK-NEXT: [0, 0, 0, 0], |
| 43 | + // CHECK-NEXT: [0, 0, 0, 0], |
| 44 | + // CHECK-NEXT: [0, 0, 0, 0]] |
| 45 | + call @printMemrefF32(%xf) : (tensor<*xf32>) -> () |
| 46 | + |
| 47 | + return |
| 48 | +} |
| 49 | + |
| 50 | +transform.sequence failures(propagate) { |
| 51 | +^bb1(%arg1: !transform.any_op): |
| 52 | + %0 = transform.structured.match ops{["linalg.matmul"]} in %arg1 : (!transform.any_op) -> !transform.any_op |
| 53 | + %func_op = get_parent_op %0 : (!transform.any_op) -> !transform.op<"func.func"> |
| 54 | + transform.structured.masked_vectorize %0 vector_sizes [4, 4, 2] : !transform.any_op |
| 55 | + transform.apply_patterns to %func_op { |
| 56 | + transform.apply_patterns.vector.lower_multi_reduction lowering_strategy = "innerreduction" |
| 57 | + } : !transform.op<"func.func"> |
| 58 | +} |
0 commit comments