|
| 1 | +// RUN: mlir-opt %s -test-transform-dialect-interpreter --cse --canonicalize -split-input-file -verify-diagnostics | FileCheck %s |
| 2 | + |
| 3 | +func.func @test(%A : tensor<128x128xf32>, %B1 : tensor<128x128xf32>, %B2 : tensor<128x128xf32>) -> (tensor<128x128xf32>, tensor<128x128xf32>) { |
| 4 | + %zero = arith.constant 0.0 : f32 |
| 5 | + %out_alloc = tensor.empty() : tensor<128x128xf32> |
| 6 | + %out = linalg.fill ins(%zero : f32) outs(%out_alloc : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 7 | + |
| 8 | + // CHECK: scf.forall ([[I:%.*]]) in (4) shared_outs([[S1:%.*]] = [[IN1:%.*]], [[S2:%.*]] = [[IN2:%.*]]) -> (tensor<128x128xf32>, tensor<128x128xf32>) { |
| 9 | + // CHECK: [[T:%.*]] = affine.apply |
| 10 | + // CHECK: tensor.extract_slice [[S1]][[[T]], 0] [32, 128] [1, 1] |
| 11 | + // CHECK: [[OUT1:%.*]] = linalg.matmul |
| 12 | + // CHECK: tensor.extract_slice [[S2]][[[T]], 0] [32, 128] [1, 1] |
| 13 | + // CHECK: [[OUT2:%.*]] = linalg.matmul |
| 14 | + // CHECK: scf.forall.in_parallel { |
| 15 | + // CHECK: tensor.parallel_insert_slice [[OUT1]] into [[S1]][[[T]], 0] [32, 128] [1, 1] |
| 16 | + // CHECK: tensor.parallel_insert_slice [[OUT2]] into [[S2]][[[T]], 0] [32, 128] [1, 1] |
| 17 | + // CHECK: } |
| 18 | + // CHECK: } |
| 19 | + %out1 = linalg.matmul ins(%A, %B1 : tensor<128x128xf32>, tensor<128x128xf32>) outs(%out : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 20 | + %out2 = linalg.matmul ins(%A, %B2 : tensor<128x128xf32>, tensor<128x128xf32>) outs(%out : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 21 | + |
| 22 | + func.return %out1, %out2 : tensor<128x128xf32>, tensor<128x128xf32> |
| 23 | +} |
| 24 | + |
| 25 | +transform.sequence failures(propagate) { |
| 26 | +^bb0(%variant_op : !transform.any_op): |
| 27 | + %matched = transform.structured.match ops{["linalg.matmul"]} in %variant_op : (!transform.any_op) -> (!transform.any_op) |
| 28 | + |
| 29 | + %mm1, %mm2 = transform.split_handle %matched : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 30 | + |
| 31 | + %loop1, %tiled_mm1 = transform.structured.tile_to_forall_op %mm1 tile_sizes [32] : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 32 | + %loop2, %tiled_mm2 = transform.structured.tile_to_forall_op %mm2 tile_sizes [32] : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 33 | + |
| 34 | + %fused_loop = transform.loop.fuse_sibling %loop1 into %loop2 : (!transform.any_op, !transform.any_op) -> !transform.any_op |
| 35 | +} |
| 36 | + |
| 37 | +// ----- |
| 38 | + |
| 39 | +func.func @test(%A : tensor<128x128xf32>, %B1 : tensor<128x128xf32>, %B2 : tensor<128x128xf32>) -> (tensor<128x128xf32>, tensor<128x128xf32>) { |
| 40 | + %zero = arith.constant 0.0 : f32 |
| 41 | + %out_alloc = tensor.empty() : tensor<128x128xf32> |
| 42 | + %out = linalg.fill ins(%zero : f32) outs(%out_alloc : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 43 | + |
| 44 | + // expected-error @below {{user of results of target should be properly dominated by source}} |
| 45 | + %out1 = linalg.matmul ins(%A, %B1 : tensor<128x128xf32>, tensor<128x128xf32>) outs(%out : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 46 | + %out2 = linalg.matmul ins(%A, %out1 : tensor<128x128xf32>, tensor<128x128xf32>) outs(%out : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 47 | + |
| 48 | + func.return %out1, %out2 : tensor<128x128xf32>, tensor<128x128xf32> |
| 49 | +} |
| 50 | + |
| 51 | +transform.sequence failures(propagate) { |
| 52 | +^bb0(%variant_op : !transform.any_op): |
| 53 | + %matched = transform.structured.match ops{["linalg.matmul"]} in %variant_op : (!transform.any_op) -> (!transform.any_op) |
| 54 | + |
| 55 | + %mm1, %mm2 = transform.split_handle %matched : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 56 | + |
| 57 | + %loop1, %tiled_mm1 = transform.structured.tile_to_forall_op %mm1 tile_sizes [32] : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 58 | + %loop2, %tiled_mm2 = transform.structured.tile_to_forall_op %mm2 tile_sizes [32] : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 59 | + |
| 60 | + %fused_loop = transform.loop.fuse_sibling %loop1 into %loop2 : (!transform.any_op, !transform.any_op) -> !transform.any_op |
| 61 | +} |
| 62 | + |
| 63 | +// ----- |
| 64 | + |
| 65 | +func.func @test(%A : tensor<128x128xf32>, %B1 : tensor<128x128xf32>, %B2 : tensor<128x128xf32>) -> (tensor<128x128xf32>, tensor<128x128xf32>) { |
| 66 | + %zero = arith.constant 0.0 : f32 |
| 67 | + %out_alloc = tensor.empty() : tensor<128x128xf32> |
| 68 | + %out = linalg.fill ins(%zero : f32) outs(%out_alloc : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 69 | + |
| 70 | + %out1 = linalg.matmul ins(%A, %B1 : tensor<128x128xf32>, tensor<128x128xf32>) outs(%out : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 71 | + // expected-error @below {{values used inside regions of target should be properly dominated by source}} |
| 72 | + %out2 = linalg.matmul ins(%A, %out1 : tensor<128x128xf32>, tensor<128x128xf32>) outs(%out : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 73 | + |
| 74 | + func.return %out1, %out2 : tensor<128x128xf32>, tensor<128x128xf32> |
| 75 | +} |
| 76 | + |
| 77 | +transform.sequence failures(propagate) { |
| 78 | +^bb0(%variant_op : !transform.any_op): |
| 79 | + %matched = transform.structured.match ops{["linalg.matmul"]} in %variant_op : (!transform.any_op) -> (!transform.any_op) |
| 80 | + |
| 81 | + %mm1, %mm2 = transform.split_handle %matched : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 82 | + |
| 83 | + %loop1, %tiled_mm1 = transform.structured.tile_to_forall_op %mm1 tile_sizes [32] : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 84 | + %loop2, %tiled_mm2 = transform.structured.tile_to_forall_op %mm2 tile_sizes [32] : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 85 | + |
| 86 | + %fused_loop = transform.loop.fuse_sibling %loop2 into %loop1 : (!transform.any_op, !transform.any_op) -> !transform.any_op |
| 87 | +} |
| 88 | + |
| 89 | +// ----- |
| 90 | + |
| 91 | +func.func @test(%A : tensor<128x128xf32>, %B1 : tensor<128x128xf32>, %B2 : tensor<128x128xf32>) -> (tensor<128x128xf32>, tensor<128x128xf32>) { |
| 92 | + %zero = arith.constant 0.0 : f32 |
| 93 | + %out_alloc = tensor.empty() : tensor<128x128xf32> |
| 94 | + %out = linalg.fill ins(%zero : f32) outs(%out_alloc : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 95 | + |
| 96 | + %out1 = linalg.matmul ins(%A, %B1 : tensor<128x128xf32>, tensor<128x128xf32>) outs(%out : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 97 | + // expected-error @below {{operands of target should be properly dominated by source}} |
| 98 | + %out2 = linalg.matmul ins(%A, %B2 : tensor<128x128xf32>, tensor<128x128xf32>) outs(%out1 : tensor<128x128xf32>) -> tensor<128x128xf32> |
| 99 | + |
| 100 | + func.return %out1, %out2 : tensor<128x128xf32>, tensor<128x128xf32> |
| 101 | +} |
| 102 | + |
| 103 | +transform.sequence failures(propagate) { |
| 104 | +^bb0(%variant_op : !transform.any_op): |
| 105 | + %matched = transform.structured.match ops{["linalg.matmul"]} in %variant_op : (!transform.any_op) -> (!transform.any_op) |
| 106 | + |
| 107 | + %mm1, %mm2 = transform.split_handle %matched : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 108 | + |
| 109 | + %loop1, %tiled_mm1 = transform.structured.tile_to_forall_op %mm1 tile_sizes [32] : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 110 | + %loop2, %tiled_mm2 = transform.structured.tile_to_forall_op %mm2 tile_sizes [32] : (!transform.any_op) -> (!transform.any_op, !transform.any_op) |
| 111 | + |
| 112 | + %fused_loop = transform.loop.fuse_sibling %loop2 into %loop1 : (!transform.any_op, !transform.any_op) -> !transform.any_op |
| 113 | +} |
0 commit comments