diff --git a/mlir/integration_test/Dialect/Vector/CPU/test-transfer-read-2d.mlir b/mlir/integration_test/Dialect/Vector/CPU/test-transfer-read-2d.mlir new file mode 100644 --- /dev/null +++ b/mlir/integration_test/Dialect/Vector/CPU/test-transfer-read-2d.mlir @@ -0,0 +1,59 @@ +// RUN: mlir-opt %s -convert-vector-to-scf -lower-affine -convert-scf-to-std -convert-vector-to-llvm | \ +// RUN: mlir-cpu-runner -e entry -entry-point-result=void \ +// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_c_runner_utils%shlibext | \ +// RUN: FileCheck %s + +func @transfer_read_2d(%A : memref<4x4xf32>, %base1: index, %base2: index) { + %fm42 = constant -42.0: f32 + %f = vector.transfer_read %A[%base1, %base2], %fm42 + {permutation_map = affine_map<(d0, d1) -> (d0, d1)>} : + memref<4x4xf32>, vector<4x4xf32> + vector.print %f: vector<4x4xf32> + return +} + +func @transfer_write_2d(%A : memref<4x4xf32>, %base1: index, %base2: index) { + %fn1 = constant -1.0 : f32 + %vf0 = splat %fn1 : vector<1x4xf32> + vector.transfer_write %vf0, %A[%base1, %base2] + {permutation_map = affine_map<(d0, d1) -> (d0, d1)>} : + vector<1x4xf32>, memref<4x4xf32> + return +} + + +func @entry() { + %c0 = constant 0: index + %c1 = constant 1: index + %c2 = constant 2: index + %c3 = constant 3: index + %c4 = constant 4: index + %c5 = constant 5: index + %f10 = constant 10.0: f32 + %A = alloc() : memref<4x4xf32> + scf.for %i = %c0 to %c4 step %c1 { + %i32 = index_cast %i : index to i32 + %fi = sitofp %i32 : i32 to f32 + %fi10 = mulf %fi, %f10 : f32 + scf.for %j = %c0 to %c4 step %c1 { + %j32 = index_cast %j : index to i32 + %fj = sitofp %j32 : i32 to f32 + %fres = addf %fi10, %fj : f32 + store %fres, %A[%i, %j] : memref<4x4xf32> + } + } + // On input, memory contains [[ 0, 1, 2, 3, 4, xxx garbage xxx ]] + // Read shifted by 2 and pad with -42: + // ( 2, 3, 4, -42, ..., -42) + call @transfer_read_2d(%A, %c1, %c2) : (memref<4x4xf32>, index, index) -> () + // Write into memory shifted by 3 + // memory contains [[ 0, 1, 2, 0, 0, xxx garbage xxx ]] + call @transfer_write_2d(%A, %c3, %c1) : (memref<4x4xf32>, index, index) -> () + // Read shifted by 0 and pad with -42: + // ( 0, 1, 2, 0, 0, -42, ..., -42) + call @transfer_read_2d(%A, %c0, %c0) : (memref<4x4xf32>, index, index) -> () + return +} + +// CHECK: ( ( 12, 13, -42, -42 ), ( 22, 23, -42, -42 ), ( 32, 33, -42, -42 ), ( -42, -42, -42, -42 ) ) +// CHECK: ( ( 0, 1, 2, 3 ), ( 10, 11, 12, 13 ), ( 20, 21, 22, 23 ), ( 30, -1, -1, -1 ) )