[Mlir-commits] [mlir] bb6afc6 - [mlir][memref] Add memref.copy operation
Stephan Herhut
llvmlistbot at llvm.org
Tue Jun 22 04:22:17 PDT 2021
Author: Stephan Herhut
Date: 2021-06-22T13:21:44+02:00
New Revision: bb6afc69b212b756b51b165672bd3531032afa01
URL: https://github.com/llvm/llvm-project/commit/bb6afc69b212b756b51b165672bd3531032afa01
DIFF: https://github.com/llvm/llvm-project/commit/bb6afc69b212b756b51b165672bd3531032afa01.diff
LOG: [mlir][memref] Add memref.copy operation
As the name suggests, it copies from one memref to another.
Differential Revision: https://reviews.llvm.org/D104657
Added:
Modified:
mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
mlir/test/Dialect/MemRef/invalid.mlir
mlir/test/Dialect/MemRef/ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
index 7bcc53d93845b..19f1c3c0d2c47 100644
--- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
+++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
@@ -444,6 +444,43 @@ def CloneOp : MemRef_Op<"clone", [
let hasCanonicalizer = 1;
}
+//===----------------------------------------------------------------------===//
+// CopyOp
+//===----------------------------------------------------------------------===//
+
+def CopyOp : MemRef_Op<"copy",
+ [CopyOpInterface, SameOperandsElementType, SameOperandsShape]> {
+
+ let description = [{
+ Copies the data from the source to the destination memref.
+
+ Usage:
+
+ ```mlir
+ memref.copy %arg0, %arg1 : memref<?xf32> to memref<?xf32>
+ ```
+
+ Source and destination are expected to have the same element type and shape.
+ Otherwise, the result is undefined. They may have
diff erent layouts.
+ }];
+
+ let arguments = (ins Arg<AnyRankedOrUnrankedMemRef, "the memref to copy from",
+ [MemRead]>:$source,
+ Arg<AnyRankedOrUnrankedMemRef, "the memref to copy to",
+ [MemWrite]>:$target);
+
+ let extraClassDeclaration = [{
+ Value getSource() { return source();}
+ Value getTarget() { return target(); }
+ }];
+
+ let assemblyFormat = [{
+ $source `,` $target attr-dict `:` type($source) `to` type($target)
+ }];
+
+ let verifier = ?;
+}
+
//===----------------------------------------------------------------------===//
// DeallocOp
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/MemRef/invalid.mlir b/mlir/test/Dialect/MemRef/invalid.mlir
index 06c1b20d52bfd..63209ef108943 100644
--- a/mlir/test/Dialect/MemRef/invalid.mlir
+++ b/mlir/test/Dialect/MemRef/invalid.mlir
@@ -215,3 +215,19 @@ func @mismatched_types() {
%0 = memref.get_global @gv : memref<3xf32>
return
}
+
+// -----
+
+func @copy_
diff erent_shape(%arg0: memref<2xf32>, %arg1: memref<3xf32>) {
+ // expected-error @+1 {{op requires the same shape for all operands}}
+ memref.copy %arg0, %arg1 : memref<2xf32> to memref<3xf32>
+ return
+}
+
+// -----
+
+func @copy_
diff erent_eltype(%arg0: memref<2xf32>, %arg1: memref<2xf16>) {
+ // expected-error @+1 {{op requires the same element type for all operands}}
+ memref.copy %arg0, %arg1 : memref<2xf32> to memref<2xf16>
+ return
+}
diff --git a/mlir/test/Dialect/MemRef/ops.mlir b/mlir/test/Dialect/MemRef/ops.mlir
index bbd7fb35a3866..993a6131ab513 100644
--- a/mlir/test/Dialect/MemRef/ops.mlir
+++ b/mlir/test/Dialect/MemRef/ops.mlir
@@ -69,6 +69,16 @@ func @memref_clone() {
return
}
+// CHECK-LABEL: func @memref_copy
+func @memref_copy() {
+ %0 = memref.alloc() : memref<2xf32>
+ %1 = memref.cast %0 : memref<2xf32> to memref<*xf32>
+ %2 = memref.alloc() : memref<2xf32>
+ %3 = memref.cast %0 : memref<2xf32> to memref<*xf32>
+ memref.copy %1, %3 : memref<*xf32> to memref<*xf32>
+ return
+}
+
// CHECK-LABEL: func @memref_dealloc
func @memref_dealloc() {
%0 = memref.alloc() : memref<2xf32>
More information about the Mlir-commits
mailing list