[Mlir-commits] [mlir] db2de8d - [mlir][llvm] Add a test for memref.copy lowering to llvm
Stephan Herhut
llvmlistbot at llvm.org
Wed Jun 30 01:49:41 PDT 2021
Author: Stephan Herhut
Date: 2021-06-30T10:49:29+02:00
New Revision: db2de8d7f1eb37f5a7c1d2de61cdd9d79647ea78
URL: https://github.com/llvm/llvm-project/commit/db2de8d7f1eb37f5a7c1d2de61cdd9d79647ea78
DIFF: https://github.com/llvm/llvm-project/commit/db2de8d7f1eb37f5a7c1d2de61cdd9d79647ea78.diff
LOG: [mlir][llvm] Add a test for memref.copy lowering to llvm
This was missing and also there was a bug in the lowering itself, which went unnoticed due to it.
Differential Revision: https://reviews.llvm.org/D105122
Added:
mlir/test/mlir-cpu-runner/copy.mlir
Modified:
mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp b/mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp
index 47a5851b51f2e..a4c8b741a3884 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp
@@ -35,7 +35,7 @@ static constexpr llvm::StringRef kPrintNewline = "printNewline";
static constexpr llvm::StringRef kMalloc = "malloc";
static constexpr llvm::StringRef kAlignedAlloc = "aligned_alloc";
static constexpr llvm::StringRef kFree = "free";
-static constexpr llvm::StringRef kMemRefCopy = "memref_copy";
+static constexpr llvm::StringRef kMemRefCopy = "memrefCopy";
/// Generic print function lookupOrCreate helper.
LLVM::LLVMFuncOp mlir::LLVM::lookupOrCreateFn(ModuleOp moduleOp, StringRef name,
diff --git a/mlir/test/mlir-cpu-runner/copy.mlir b/mlir/test/mlir-cpu-runner/copy.mlir
new file mode 100644
index 0000000000000..508e7b264ae1c
--- /dev/null
+++ b/mlir/test/mlir-cpu-runner/copy.mlir
@@ -0,0 +1,49 @@
+// RUN: mlir-opt %s -convert-scf-to-std -convert-std-to-llvm \
+// RUN: | mlir-cpu-runner -e main -entry-point-result=void \
+// RUN: -shared-libs=%mlir_runner_utils_dir/libmlir_runner_utils%shlibext,%mlir_runner_utils_dir/libmlir_c_runner_utils%shlibext \
+// RUN: | FileCheck %s
+
+func private @print_memref_f32(memref<*xf32>) attributes { llvm.emit_c_interface }
+
+func @main() -> () {
+ %c0 = constant 0 : index
+ %c1 = constant 1 : index
+
+ // Initialize input.
+ %input = memref.alloc() : memref<2x3xf32>
+ %dim_x = memref.dim %input, %c0 : memref<2x3xf32>
+ %dim_y = memref.dim %input, %c1 : memref<2x3xf32>
+ scf.parallel (%i, %j) = (%c0, %c0) to (%dim_x, %dim_y) step (%c1, %c1) {
+ %prod = muli %i, %dim_y : index
+ %val = addi %prod, %j : index
+ %val_i64 = index_cast %val : index to i64
+ %val_f32 = sitofp %val_i64 : i64 to f32
+ memref.store %val_f32, %input[%i, %j] : memref<2x3xf32>
+ }
+ %unranked_input = memref.cast %input : memref<2x3xf32> to memref<*xf32>
+ call @print_memref_f32(%unranked_input) : (memref<*xf32>) -> ()
+ // CHECK: rank = 2 offset = 0 sizes = [2, 3] strides = [3, 1]
+ // CHECK-NEXT: [0, 1, 2]
+ // CHECK-NEXT: [3, 4, 5]
+
+ %copy = memref.alloc() : memref<2x3xf32>
+ memref.copy %input, %copy : memref<2x3xf32> to memref<2x3xf32>
+ %unranked_copy = memref.cast %copy : memref<2x3xf32> to memref<*xf32>
+ call @print_memref_f32(%unranked_copy) : (memref<*xf32>) -> ()
+ // CHECK: rank = 2 offset = 0 sizes = [2, 3] strides = [3, 1]
+ // CHECK-NEXT: [0, 1, 2]
+ // CHECK-NEXT: [3, 4, 5]
+
+ %copy_two = memref.alloc() : memref<3x2xf32>
+ %copy_two_casted = memref.reinterpret_cast %copy_two to offset: [0], sizes: [2,3], strides:[1, 2]
+ : memref<3x2xf32> to memref<2x3xf32>
+ memref.copy %input, %copy_two_casted : memref<2x3xf32> to memref<2x3xf32>
+ %unranked_copy_two = memref.cast %copy_two : memref<3x2xf32> to memref<*xf32>
+ call @print_memref_f32(%unranked_copy_two) : (memref<*xf32>) -> ()
+ // CHECK: rank = 2 offset = 0 sizes = [3, 2] strides = [2, 1]
+ // CHECK-NEXT: [0, 3]
+ // CHECK-NEXT: [1, 4]
+ // CHECK-NEXT: [2, 5]
+
+ return
+}
More information about the Mlir-commits
mailing list