155 lines · plain
1// RUN: mlir-opt %s -test-lower-to-llvm | \2// RUN: mlir-runner -e entry -entry-point-result=void \3// RUN: -shared-libs=%mlir_c_runner_utils | \4// RUN: FileCheck %s5 6func.func @transfer_write16_inbounds_1d(%A : memref<?xf32>, %base: index) {7 %f = arith.constant 16.0 : f328 %v = vector.broadcast %f : f32 to vector<16xf32>9 vector.transfer_write %v, %A[%base]10 {permutation_map = affine_map<(d0) -> (d0)>, in_bounds = [true]}11 : vector<16xf32>, memref<?xf32>12 return13}14 15func.func @transfer_write13_1d(%A : memref<?xf32>, %base: index) {16 %f = arith.constant 13.0 : f3217 %v = vector.broadcast %f : f32 to vector<13xf32>18 vector.transfer_write %v, %A[%base]19 {permutation_map = affine_map<(d0) -> (d0)>}20 : vector<13xf32>, memref<?xf32>21 return22}23 24func.func @transfer_write17_1d(%A : memref<?xf32>, %base: index) {25 %f = arith.constant 17.0 : f3226 %v = vector.broadcast %f : f32 to vector<17xf32>27 vector.transfer_write %v, %A[%base]28 {permutation_map = affine_map<(d0) -> (d0)>}29 : vector<17xf32>, memref<?xf32>30 return31}32 33func.func @transfer_read_1d(%A : memref<?xf32>) -> vector<32xf32> {34 %z = arith.constant 0: index35 %f = arith.constant 0.0: f3236 %r = vector.transfer_read %A[%z], %f37 {permutation_map = affine_map<(d0) -> (d0)>}38 : memref<?xf32>, vector<32xf32>39 return %r : vector<32xf32>40}41 42func.func @transfer_write_inbounds_3d(%A : memref<4x4x4xf32>) {43 %c0 = arith.constant 0: index44 %f = arith.constant 0.0 : f3245 %v0 = vector.broadcast %f : f32 to vector<2x3x4xf32>46 %f1 = arith.constant 1.0 : f3247 %f2 = arith.constant 2.0 : f3248 %f3 = arith.constant 3.0 : f3249 %f4 = arith.constant 4.0 : f3250 %f5 = arith.constant 5.0 : f3251 %f6 = arith.constant 6.0 : f3252 %f7 = arith.constant 7.0 : f3253 %f8 = arith.constant 8.0 : f3254 55 %v1 = vector.insert %f1, %v0[0, 0, 0] : f32 into vector<2x3x4xf32>56 %v2 = vector.insert %f2, %v1[0, 0, 3] : f32 into vector<2x3x4xf32>57 %v3 = vector.insert %f3, %v2[0, 2, 0] : f32 into vector<2x3x4xf32>58 %v4 = vector.insert %f4, %v3[0, 2, 3] : f32 into vector<2x3x4xf32>59 %v5 = vector.insert %f5, %v4[1, 0, 0] : f32 into vector<2x3x4xf32>60 %v6 = vector.insert %f6, %v5[1, 0, 3] : f32 into vector<2x3x4xf32>61 %v7 = vector.insert %f7, %v6[1, 2, 0] : f32 into vector<2x3x4xf32>62 %v8 = vector.insert %f8, %v7[1, 2, 3] : f32 into vector<2x3x4xf32>63 vector.transfer_write %v8, %A[%c0, %c0, %c0]64 {permutation_map = affine_map<(d0, d1, d2) -> (d2, d0, d1)>,65 in_bounds = [true, true, true]}66 : vector<2x3x4xf32>, memref<4x4x4xf32>67 return68}69 70func.func @entry() {71 %c0 = arith.constant 0: index72 %c1 = arith.constant 1: index73 %c32 = arith.constant 32: index74 %A = memref.alloc(%c32) {alignment=64} : memref<?xf32>75 scf.for %i = %c0 to %c32 step %c1 {76 %f = arith.constant 0.0: f3277 memref.store %f, %A[%i] : memref<?xf32>78 }79 80 // On input, memory contains all zeros.81 %0 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)82 vector.print %0 : vector<32xf32>83 84 // Overwrite with 16 values of 16 at base 3.85 // Statically guaranteed to be in-bounds. Exercises proper alignment.86 %c3 = arith.constant 3: index87 call @transfer_write16_inbounds_1d(%A, %c3) : (memref<?xf32>, index) -> ()88 %1 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)89 vector.print %1 : vector<32xf32>90 91 // Overwrite with 13 values of 13 at base 3.92 call @transfer_write13_1d(%A, %c3) : (memref<?xf32>, index) -> ()93 %2 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)94 vector.print %2 : vector<32xf32>95 96 // Overwrite with 17 values of 17 at base 7.97 %c7 = arith.constant 7: index98 call @transfer_write17_1d(%A, %c3) : (memref<?xf32>, index) -> ()99 %3 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)100 vector.print %3 : vector<32xf32>101 102 // Overwrite with 13 values of 13 at base 8.103 %c8 = arith.constant 8: index104 call @transfer_write13_1d(%A, %c8) : (memref<?xf32>, index) -> ()105 %4 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)106 vector.print %4 : vector<32xf32>107 108 // Overwrite with 17 values of 17 at base 14.109 %c14 = arith.constant 14: index110 call @transfer_write17_1d(%A, %c14) : (memref<?xf32>, index) -> ()111 %5 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)112 vector.print %5 : vector<32xf32>113 114 // Overwrite with 13 values of 13 at base 19.115 %c19 = arith.constant 19: index116 call @transfer_write13_1d(%A, %c19) : (memref<?xf32>, index) -> ()117 %6 = call @transfer_read_1d(%A) : (memref<?xf32>) -> (vector<32xf32>)118 vector.print %6 : vector<32xf32>119 120 memref.dealloc %A : memref<?xf32>121 122 // 3D case123 %c4 = arith.constant 4: index124 %A1 = memref.alloc() {alignment=64} : memref<4x4x4xf32>125 scf.for %i = %c0 to %c4 step %c1 {126 scf.for %j = %c0 to %c4 step %c1 {127 scf.for %k = %c0 to %c4 step %c1 {128 %f = arith.constant 0.0: f32129 memref.store %f, %A1[%i, %j, %k] : memref<4x4x4xf32>130 }131 }132 }133 call @transfer_write_inbounds_3d(%A1) : (memref<4x4x4xf32>) -> ()134 %f = arith.constant 0.0: f32135 %r = vector.transfer_read %A1[%c0, %c0, %c0], %f136 : memref<4x4x4xf32>, vector<4x4x4xf32>137 vector.print %r : vector<4x4x4xf32>138 139 memref.dealloc %A1 : memref<4x4x4xf32>140 141 return142}143 144// CHECK: ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )145// CHECK: ( 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )146// CHECK: ( 0, 0, 0, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )147// CHECK: ( 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )148// CHECK: ( 0, 0, 0, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )149// CHECK: ( 0, 0, 0, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 0 )150// CHECK: ( 0, 0, 0, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13, 17, 17, 17, 17, 17, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13 )151 152// 3D case.153// CHECK: ( ( ( 1, 5, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 2, 6, 0, 0 ) ), ( ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ) ),154// CHECK-SAME: ( ( 3, 7, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 4, 8, 0, 0 ) ), ( ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ) ) )155