brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.1 KiB · 03aba89 Raw
105 lines · plain
1// RUN: mlir-opt %s --transform-interpreter --split-input-file | FileCheck %s2 3func.func @matmul(%lhs: memref<32x32xf32>, %rhs: memref<32x32xf32>, %out: memref<32x32xf32>) {4  %c8 = arith.constant 8 : index5  %c0 = arith.constant 0 : index6  %cst = arith.constant dense<0.000000e+00> : vector<16x16xf32>7  %c16 = arith.constant 16 : index8  %c32 = arith.constant 32 : index9  %cst_0 = arith.constant 0.000000e+00 : f3210  %3 = gpu.thread_id  x11  %4 = gpu.thread_id  y12  %5 = affine.apply affine_map<()[s0] -> (s0 * 16)>()[%4]13  %6 = affine.apply affine_map<()[s0] -> ((s0 floordiv 32) * 16)>()[%3]14  // CHECK:         scf.for {{.*}} -> (vector<16x16xf32>) {15  // CHECK-COUNT-2:   vector.transfer_read {{.*}} vector<16x8xf32>16  // CHECK-COUNT-2:   vector.transfer_read {{.*}} vector<8x16xf32>17  // CHECK-COUNT-2:   vector.contract {{.*}} vector<16x8xf32>, vector<8x16xf32> into vector<16x16xf32>18  // CHECK:           scf.yield {{.*}} : vector<16x16xf32>19  // CHECK:         }20  %7 = scf.for %arg0 = %c0 to %c32 step %c16 iter_args(%arg1 = %cst) -> (vector<16x16xf32>) {21    %10 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%5]22    %11 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%arg0]23    %12 = vector.transfer_read %lhs[%10, %11], %cst_0 {in_bounds = [true, true]} : memref<32x32xf32>, vector<16x16xf32>24    %16 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%6]25    %17 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%arg0]26    %18 = vector.transfer_read %rhs[%17, %16], %cst_0 {in_bounds = [true, true]} : memref<32x32xf32>, vector<16x16xf32>27    %22 = vector.contract {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d2, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction"], kind = #vector.kind<add>} %12, %18, %arg1 : vector<16x16xf32>, vector<16x16xf32> into vector<16x16xf32>28    scf.yield %22 : vector<16x16xf32>29  }30  %8 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%5]31  %9 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%6]32  vector.transfer_write %7, %out[%8, %9] {in_bounds = [true, true]} : vector<16x16xf32>, memref<32x32xf32>33  return34}35 36module attributes {transform.with_named_sequence} {37  transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {38    %func_op = transform.structured.match ops{["func.func"]} in %arg0 : (!transform.any_op) -> !transform.op<"func.func">39    transform.apply_patterns to %func_op {40      transform.apply_patterns.gpu.unroll_vectors_subgroup_mma [16, 16, 8]41    } : !transform.op<"func.func">42    transform.yield43  }44}45 46// -----47 48// CHECK-LABEL: func.func @gathered_matmul49func.func @gathered_matmul(%lhs: memref<32x32xf32>, %rhs: memref<32x32xf32>, %out: memref<32x32xf32>) {50  %c8 = arith.constant 8 : index51  %c0 = arith.constant 0 : index52  %cst = arith.constant dense<0.000000e+00> : vector<16x16xf32>53  %cst_mask = arith.constant dense<true> : vector<4x4xi1>54  %cst_pt = arith.constant dense<0.000000e+00> : vector<4x4xf32>55  %c16 = arith.constant 16 : index56  %c32 = arith.constant 32 : index57  %cst_0 = arith.constant 0.000000e+00 : f3258  %cst_1 = arith.constant dense<[0, 1, 2, 3]> : vector<4xindex>59  %cst_2 = arith.constant dense<1> : vector<4x4xindex>60  %alloc = memref.alloc() {alignment = 64 : i64} : memref<32x32xf32>61  %3 = gpu.thread_id  x62  %4 = gpu.thread_id  y63  %5 = affine.apply affine_map<()[s0] -> (s0 * 16)>()[%4]64  %6 = affine.apply affine_map<()[s0] -> ((s0 floordiv 32) * 16)>()[%3]65  // CHECK:         scf.for {{.*}} -> (vector<16x16xf32>) {66  // CHECK:           arith.addi {{.*}} : vector<4xindex>67  // CHECK:           vector.gather {{.*}} : memref<32x32xf32>, vector<4x4xindex>, vector<4x4xi1>, vector<4x4xf32> into vector<4x4xf32>68  // CHECK-COUNT-8:   vector.transfer_read {{.*}} vector<8x4xf32>69  // CHECK-COUNT-4:   vector.transfer_read {{.*}} vector<4x16xf32>70  // CHECK-COUNT-8:   vector.contract {{.*}} vector<8x4xf32>, vector<4x16xf32> into vector<8x16xf32>71  // CHECK:           scf.yield {{.*}} : vector<16x16xf32>72  // CHECK:         }73  %7 = scf.for %arg0 = %c0 to %c32 step %c16 iter_args(%arg1 = %cst) -> (vector<16x16xf32>) {74    %10 = vector.broadcast %arg0 : index to vector<4xindex>75    %11 = arith.addi %10, %cst_1 : vector<4xindex>76    %12 = vector.broadcast %11 : vector<4xindex> to vector<4x4xindex>77    %13 = arith.addi %12, %cst_2 : vector<4x4xindex>78    %14 = vector.gather %lhs[%c0, %c0] [%13], %cst_mask, %cst_pt : memref<32x32xf32>, vector<4x4xindex>, vector<4x4xi1>, vector<4x4xf32> into vector<4x4xf32>79    vector.transfer_write %14, %alloc[%c0, %c0] {in_bounds = [true, true]} : vector<4x4xf32>, memref<32x32xf32>80    gpu.barrier81    %15 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%5]82    %16 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%arg0]83    %17 = vector.transfer_read %alloc[%15, %16], %cst_0 {in_bounds = [true, true]} : memref<32x32xf32>, vector<16x16xf32>84    %18 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%6]85    %19 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%arg0]86    %20 = vector.transfer_read %rhs[%19, %18], %cst_0 {in_bounds = [true, true]} : memref<32x32xf32>, vector<16x16xf32>87    %21 = vector.contract {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d2, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "reduction"], kind = #vector.kind<add>} %17, %20, %arg1 : vector<16x16xf32>, vector<16x16xf32> into vector<16x16xf32>88    scf.yield %21 : vector<16x16xf32>89  }90  %8 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%5]91  %9 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%c0)[%6]92  vector.transfer_write %7, %out[%8, %9] {in_bounds = [true, true]} : vector<16x16xf32>, memref<32x32xf32>93  return94}95 96module attributes {transform.with_named_sequence} {97  transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {98    %func_op = transform.structured.match ops{["func.func"]} in %arg0 : (!transform.any_op) -> !transform.op<"func.func">99    transform.apply_patterns to %func_op {100      transform.apply_patterns.gpu.unroll_vectors_subgroup_mma [8, 16, 4]101    } : !transform.op<"func.func">102    transform.yield103  }104}105