|
| 1 | +// DEFINE: %{entry_point} = entry |
| 2 | +// DEFINE: %{compile} = mlir-opt %s \ |
| 3 | +// DEFINE: -enable-arm-streaming="mode=locally enable-za" \ |
| 4 | +// DEFINE: -convert-vector-to-arm-sme -convert-arm-sme-to-scf \ |
| 5 | +// DEFINE: -convert-vector-to-llvm="enable-arm-sme" -cse -canonicalize \ |
| 6 | +// DEFINE: -allocate-arm-sme-tiles -test-lower-to-llvm |
| 7 | +// DEFINE: %{run} = %mcr_aarch64_cmd \ |
| 8 | +// DEFINE: -march=aarch64 -mattr=+sve,+sme \ |
| 9 | +// DEFINE: -e %{entry_point} -entry-point-result=void \ |
| 10 | +// DEFINE: -shared-libs=%mlir_runner_utils,%mlir_c_runner_utils |
| 11 | + |
| 12 | +// RUN: %{compile} | %{run} | FileCheck %s |
| 13 | + |
| 14 | +// Vector store. |
| 15 | +func.func @transfer_write_2d(%A : memref<?x?xf32>, %base1: index, %base2: index) { |
| 16 | + %c0 = arith.constant 0.0 : f32 |
| 17 | + %zero = vector.splat %c0 : vector<[4]x[4]xf32> |
| 18 | + vector.transfer_write %zero, %A[%base1, %base2] {in_bounds=[true, true]} : |
| 19 | + vector<[4]x[4]xf32>, memref<?x?xf32> |
| 20 | + return |
| 21 | +} |
| 22 | + |
| 23 | +// Masked vector store. |
| 24 | +func.func @transfer_write_2d_mask(%A : memref<?x?xf32>, %base1: index, %base2: index) { |
| 25 | + %c0 = arith.constant 0.0 : f32 |
| 26 | + %c2 = arith.constant 2 : index |
| 27 | + %c3 = arith.constant 3 : index |
| 28 | + %mask = vector.create_mask %c2, %c3 : vector<[4]x[4]xi1> |
| 29 | + %zero = vector.splat %c0 : vector<[4]x[4]xf32> |
| 30 | + vector.transfer_write %zero, %A[%base1, %base2], %mask {in_bounds=[true, true]} : |
| 31 | + vector<[4]x[4]xf32>, memref<?x?xf32> |
| 32 | + return |
| 33 | +} |
| 34 | + |
| 35 | +// Vector load + print. |
| 36 | +func.func @load_and_print(%A : memref<?x?xf32>, %base1: index, %base2: index) { |
| 37 | + %0 = vector.load %A[%base1, %base2] : memref<?x?xf32>, vector<[4]x[4]xf32> |
| 38 | + |
| 39 | + vector.print str "TILE BEGIN:" |
| 40 | + vector.print %0: vector<[4]x[4]xf32> |
| 41 | + |
| 42 | + return |
| 43 | +} |
| 44 | + |
| 45 | +// Allocate heap memory of size 'd0' x 'd1' and initialize. |
| 46 | +// |
| 47 | +// Example: |
| 48 | +// |
| 49 | +// initialize_memory(%c4, %c5) |
| 50 | +// |
| 51 | +// 0, 1, 2, 3, 4 |
| 52 | +// 10, 11, 12, 13, 14 |
| 53 | +// 20, 21, 22, 23, 24 |
| 54 | +// 30, 31, 32, 33, 34 |
| 55 | +// |
| 56 | +// Returns dynamic memref. It's the callers responsiblity to free the returned |
| 57 | +// memref. |
| 58 | +func.func @initialize_memory(%d0 : index, %d1 : index) -> memref<?x?xf32> { |
| 59 | + %c0 = arith.constant 0 : index |
| 60 | + %c1 = arith.constant 1 : index |
| 61 | + %c1_f32 = arith.constant 1.0 : f32 |
| 62 | + %c10_f32 = arith.constant 10.0 : f32 |
| 63 | + |
| 64 | + %A = memref.alloc(%d0, %d1) : memref<?x?xf32> |
| 65 | + |
| 66 | + %init = arith.constant 0.0 : f32 |
| 67 | + scf.for %i = %c0 to %d0 step %c1 iter_args(%val = %init) -> f32 { |
| 68 | + scf.for %j = %c0 to %d1 step %c1 iter_args(%inner_val = %val) -> f32 { |
| 69 | + memref.store %inner_val, %A[%i, %j] : memref<?x?xf32> |
| 70 | + %inner_val_next = arith.addf %inner_val, %c1_f32 : f32 |
| 71 | + scf.yield %inner_val_next : f32 |
| 72 | + } |
| 73 | + %val_next = arith.addf %val, %c10_f32 : f32 |
| 74 | + scf.yield %val_next : f32 |
| 75 | + } |
| 76 | + |
| 77 | + return %A : memref<?x?xf32> |
| 78 | +} |
| 79 | + |
| 80 | +func.func @entry() { |
| 81 | + %c0 = arith.constant 0 : index |
| 82 | + %c2 = arith.constant 2 : index |
| 83 | + %c4 = arith.constant 4 : index |
| 84 | + |
| 85 | + // 1. Initialize memory |
| 86 | + // |
| 87 | + // Allocate enough memory to load a 32-bit tile plus a tiny bit more to test |
| 88 | + // non-zero offsets while remaining inbounds. |
| 89 | + %vscale = vector.vscale |
| 90 | + %svl_s = arith.muli %c4, %vscale : index |
| 91 | + %svl_s_plus_two = arith.addi %svl_s, %c2 : index |
| 92 | + %A = call @initialize_memory(%svl_s_plus_two, %svl_s_plus_two) : (index, index) -> memref<?x?xf32> |
| 93 | + |
| 94 | + // CHECK-LABEL: TILE BEGIN: |
| 95 | + // CHECK-NEXT: ( 0, 1, 2, 3 |
| 96 | + // CHECK-NEXT: ( 10, 11, 12, 13 |
| 97 | + // CHECK-NEXT: ( 20, 21, 22, 23 |
| 98 | + // CHECK-NEXT: ( 30, 31, 32, 33 |
| 99 | + call @load_and_print(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () |
| 100 | + |
| 101 | + // 2. Write 2-D vector of zeroes to 1. at offset [2, 2]. |
| 102 | + // CHECK-LABEL: TILE BEGIN: |
| 103 | + // CHECK-NEXT: ( 0, 1, 2, 3 |
| 104 | + // CHECK-NEXT: ( 10, 11, 12, 13 |
| 105 | + // CHECK-NEXT: ( 20, 21, 0, 0 |
| 106 | + // CHECK-NEXT: ( 30, 31, 0, 0 |
| 107 | + call @transfer_write_2d(%A, %c2, %c2) : (memref<?x?xf32>, index, index) -> () |
| 108 | + call @load_and_print(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () |
| 109 | + |
| 110 | + // 3. Write 2-D vector of zeroes to 2. but with mask (nrows=2, ncols=3). |
| 111 | + // CHECK-LABEL: TILE BEGIN: |
| 112 | + // CHECK-NEXT: ( 0, 0, 0, 3 |
| 113 | + // CHECK-NEXT: ( 0, 0, 0, 13 |
| 114 | + // CHECK-NEXT: ( 20, 21, 0, 0 |
| 115 | + // CHECK-NEXT: ( 30, 31, 0, 0 |
| 116 | + call @transfer_write_2d_mask(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () |
| 117 | + call @load_and_print(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () |
| 118 | + |
| 119 | + memref.dealloc %A : memref<?x?xf32> |
| 120 | + |
| 121 | + return |
| 122 | +} |
0 commit comments