1// RUN: mlir-opt %s -convert-vector-to-scf -lower-affine -convert-scf-to-std -convert-vector-to-llvm | \ 2// RUN: mlir-cpu-runner -e entry -entry-point-result=void \ 3// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext | \ 4// RUN: FileCheck %s 5 6func @transfer_read_2d(%A : memref<?x?xf32>, %base1: index, %base2: index) { 7 %fm42 = constant -42.0: f32 8 %f = vector.transfer_read %A[%base1, %base2], %fm42 9 {permutation_map = affine_map<(d0, d1) -> (d0, d1)>} : 10 memref<?x?xf32>, vector<4x9xf32> 11 vector.print %f: vector<4x9xf32> 12 return 13} 14 15func @transfer_write_2d(%A : memref<?x?xf32>, %base1: index, %base2: index) { 16 %fn1 = constant -1.0 : f32 17 %vf0 = splat %fn1 : vector<1x4xf32> 18 vector.transfer_write %vf0, %A[%base1, %base2] 19 {permutation_map = affine_map<(d0, d1) -> (d0, d1)>} : 20 vector<1x4xf32>, memref<?x?xf32> 21 return 22} 23 24func @entry() { 25 %c0 = constant 0: index 26 %c1 = constant 1: index 27 %c2 = constant 2: index 28 %c3 = constant 3: index 29 %c4 = constant 4: index 30 %c5 = constant 5: index 31 %c8 = constant 5: index 32 %f10 = constant 10.0: f32 33 // work with dims of 4, not of 3 34 %first = constant 3: index 35 %second = constant 4: index 36 %A = alloc(%first, %second) : memref<?x?xf32> 37 scf.for %i = %c0 to %first step %c1 { 38 %i32 = index_cast %i : index to i32 39 %fi = sitofp %i32 : i32 to f32 40 %fi10 = mulf %fi, %f10 : f32 41 scf.for %j = %c0 to %second step %c1 { 42 %j32 = index_cast %j : index to i32 43 %fj = sitofp %j32 : i32 to f32 44 %fres = addf %fi10, %fj : f32 45 store %fres, %A[%i, %j] : memref<?x?xf32> 46 } 47 } 48 // On input, memory contains [[ 0, 1, 2, ...], [10, 11, 12, ...], ...] 49 // Read shifted by 2 and pad with -42: 50 call @transfer_read_2d(%A, %c1, %c2) : (memref<?x?xf32>, index, index) -> () 51 // Write into memory shifted by 3 52 call @transfer_write_2d(%A, %c3, %c1) : (memref<?x?xf32>, index, index) -> () 53 // Read shifted by 0 and pad with -42: 54 call @transfer_read_2d(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () 55 return 56} 57 58// CHECK: ( ( 12, 13, -42, -42, -42, -42, -42, -42, -42 ), ( 22, 23, -42, -42, -42, -42, -42, -42, -42 ), ( -42, -42, -42, -42, -42, -42, -42, -42, -42 ), ( -42, -42, -42, -42, -42, -42, -42, -42, -42 ) ) 59// CHECK: ( ( 0, 1, 2, 3, -42, -42, -42, -42, -42 ), ( 10, 11, 12, 13, -42, -42, -42, -42, -42 ), ( 20, 21, 22, 23, -42, -42, -42, -42, -42 ), ( -42, -42, -42, -42, -42, -42, -42, -42, -42 ) ) 60