brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · 38e406a Raw
72 lines · plain
1// RUN: mlir-opt %s -split-input-file --linalg-specialize-generic-ops | FileCheck %s2 3#projection = affine_map<(d0, d1, d2, d3, d4) -> (d2, d3, d1)>4#identity   = affine_map<(d0, d1, d2, d3, d4) -> (d0, d1, d2, d3, d4)>5 6func.func @transpose_and_broadcast(%x : tensor<7x8x9xf32>, %y:  tensor<5x9x7x8x10xf32>, %z :  tensor<5x9x7x8x10xf32>) ->  tensor<5x9x7x8x10xf32> {7  %res = linalg.generic8     { indexing_maps = [#projection, #identity, #identity], iterator_types = ["parallel", "parallel", "parallel", "parallel", "parallel"]}9     ins(%x, %y : tensor<7x8x9xf32>, tensor<5x9x7x8x10xf32>) outs(%z : tensor<5x9x7x8x10xf32>) {10     ^bb0(%in: f32, %in_1: f32, %out: f32):11       %div = arith.divf %in, %in_1 : f3212       linalg.yield %div : f3213  } -> tensor<5x9x7x8x10xf32>14  return %res : tensor<5x9x7x8x10xf32>15}16 17// CHECK-LABEL: transpose_and_broadcast18// CHECK-SAME: %[[X:.+]]: tensor<7x8x9xf32>, %[[Y:.+]]: tensor<5x9x7x8x10xf32>, %[[Z:.+]]: tensor<5x9x7x8x10xf32>) -> tensor<5x9x7x8x10xf32> {19// CHECK: %[[E0:.+]] = tensor.empty() : tensor<9x7x8xf32>20// CHECK: %[[X_trans:.+]] = linalg.transpose ins(%[[X]] : tensor<7x8x9xf32>) outs(%[[E0]] : tensor<9x7x8xf32>) permutation = [2, 0, 1]21// CHECK: %[[E1:.+]] = tensor.empty() : tensor<5x9x7x8x10xf32>22// CHECK: %[[X_trans_bc:.+]] = linalg.broadcast ins(%[[X_trans]] : tensor<9x7x8xf32>) outs(%[[E1]] : tensor<5x9x7x8x10xf32>) dimensions = [0, 4]23// CHECK: {{.*}} = linalg.div ins(%[[X_trans_bc]], %[[Y]] : tensor<5x9x7x8x10xf32>, tensor<5x9x7x8x10xf32>) outs(%[[Z]] : tensor<5x9x7x8x10xf32>) -> tensor<5x9x7x8x10xf32>24// CHECK-NOT: linalg.generic25 26// -----27 28#identity = affine_map<(d0, d1, d2) -> (d0, d1, d2)>29#transposed = affine_map<(d0, d1, d2) -> (d2, d0, d1)>30 31func.func @transpose_only(%x : tensor<32x2x16xf32>, %y:  tensor<2x16x32xf32>, %z :  tensor<2x16x32xf32>) ->  tensor<2x16x32xf32> {32  %res = linalg.generic33     { indexing_maps = [#transposed, #identity, #identity], iterator_types = ["parallel", "parallel", "parallel"]}34     ins(%x, %y : tensor<32x2x16xf32>, tensor<2x16x32xf32>)35     outs(%z : tensor<2x16x32xf32>) {36     ^bb0(%in: f32, %in_1: f32, %out: f32):37       %div = arith.divf %in, %in_1 : f3238       linalg.yield %div : f3239  } -> tensor<2x16x32xf32>40  return %res : tensor<2x16x32xf32>41}42 43// CHECK-LABEL: transpose_only44// CHECK-SAME: %[[X:.+]]: tensor<32x2x16xf32>, %[[Y:.+]]: tensor<2x16x32xf32>, %[[Z:.+]]: tensor<2x16x32xf32>) -> tensor<2x16x32xf32> {45// CHECK: %[[E0:.+]] = tensor.empty() : tensor<2x16x32xf32>46// CHECK: %[[X_trans:.+]] = linalg.transpose ins(%[[X]] : tensor<32x2x16xf32>) outs(%[[E0]] : tensor<2x16x32xf32>) permutation = [1, 2, 0]47// CHECK: {{.*}} = linalg.div ins(%[[X_trans]], %[[Y]] : tensor<2x16x32xf32>, tensor<2x16x32xf32>) outs(%[[Z]] : tensor<2x16x32xf32>) -> tensor<2x16x32xf32>48// CHECK-NOT: linalg.generic49 50// -----51 52#identity = affine_map<(d0, d1, d2) -> (d0, d1, d2)>53#broadcast = affine_map<(d0, d1, d2) -> (d0, d2)>54func.func @broadcast_only(%x : tensor<2x16x32xf32>, %y:  tensor<2x32xf32>, %z :  tensor<2x16x32xf32>) ->  tensor<2x16x32xf32> {55  %res = linalg.generic56     { indexing_maps = [#identity, #broadcast, #identity], iterator_types = ["parallel", "parallel", "parallel"]}57     ins(%x, %y : tensor<2x16x32xf32>, tensor<2x32xf32>)58     outs(%z : tensor<2x16x32xf32>) {59     ^bb0(%in: f32, %in_1: f32, %out: f32):60       %div = arith.divf %in, %in_1 : f3261       linalg.yield %div : f3262  } -> tensor<2x16x32xf32>63  return %res : tensor<2x16x32xf32>64}65 66// CHECK-LABEL: broadcast_only67// CHECK-SAME: %[[X:.+]]: tensor<2x16x32xf32>, %[[Y:.+]]: tensor<2x32xf32>, %[[Z:.+]]: tensor<2x16x32xf32>) -> tensor<2x16x32xf32> {68// CHECK: %[[E0:.+]] = tensor.empty() : tensor<2x16x32xf32>69// CHECK: %[[X_bc:.+]] = linalg.broadcast ins(%[[Y]] : tensor<2x32xf32>) outs(%[[E0]] : tensor<2x16x32xf32>) dimensions = [1]70// CHECK: {{.*}} = linalg.div ins(%[[X]], %[[X_bc]] : tensor<2x16x32xf32>, tensor<2x16x32xf32>) outs(%arg2 : tensor<2x16x32xf32>) -> tensor<2x16x32xf32>71// CHECK-NOT: linalg.generic72