[Mlir-commits] [mlir] e3ea2d7 - [mlir][Linalg] Add basic lowering test to library calls

Nicolas Vasilache llvmlistbot at llvm.org
Thu Jun 24 03:56:56 PDT 2021


Author: Nicolas Vasilache
Date: 2021-06-24T10:56:48Z
New Revision: e3ea2d706198c37b1564533676a5f85e4576504a

URL: https://github.com/llvm/llvm-project/commit/e3ea2d706198c37b1564533676a5f85e4576504a
DIFF: https://github.com/llvm/llvm-project/commit/e3ea2d706198c37b1564533676a5f85e4576504a.diff

LOG: [mlir][Linalg] Add basic lowering test to library calls

This test shows how convert-linalg-to-std rewrites named linalg ops as library calls.
This can be coupled with a C++ shim to connect to existing libraries such as https://gist.github.com/nicolasvasilache/691ef992404c49dc9b5d543c4aa6db38.
Everything can then be linked together with mlir-cpu-runner and MLIR can call C++ (which can itself call MLIR if needed).

This should evolve into specific rewrite patterns that can be applied on op instances independently rather than having to use a full conversion.

Differential Revision: https://reviews.llvm.org/D104842

Added: 
    mlir/test/Dialect/Linalg/library-calls.mlir

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/mlir/test/Dialect/Linalg/library-calls.mlir b/mlir/test/Dialect/Linalg/library-calls.mlir
new file mode 100644
index 0000000000000..1cdf169213082
--- /dev/null
+++ b/mlir/test/Dialect/Linalg/library-calls.mlir
@@ -0,0 +1,24 @@
+// RUN: mlir-opt %s -convert-linalg-to-std | FileCheck %s
+
+func private @print_memref_f32(memref<*xf32>)
+
+// CHECK:  func private @linalg_fill_f32_viewsxsxf32(f32, memref<?x?xf32, {{.*}}>) attributes {llvm.emit_c_interface}
+// CHECK:  func private @linalg_matmul_viewsxsxf32_viewsxsxf32_viewsxsxf32(memref<?x?xf32, {{.*}}>, memref<?x?xf32, {{.*}}>, memref<?x?xf32, {{.*}}>) attributes {llvm.emit_c_interface}
+
+func @matmul(%A: memref<?x?xf32>, %B: memref<?x?xf32>) -> (memref<?x?xf32>) {
+  %c0 = constant 0 : index
+  %c1 = constant 1 : index
+  %f0 = constant 0.0 : f32
+  %x = memref.dim %A, %c0 : memref<?x?xf32>
+  %y = memref.dim %B, %c1 : memref<?x?xf32>
+  %C = memref.alloc(%x, %y) : memref<?x?xf32>
+
+  // CHECK: call @linalg_fill_f32_viewsxsxf32({{.*}}) : (f32, memref<?x?xf32, {{.*}}>)
+  linalg.fill(%f0, %C) : f32, memref<?x?xf32>
+
+  // CHECK:  call @linalg_matmul_viewsxsxf32_viewsxsxf32_viewsxsxf32({{.*}}) : (memref<?x?xf32, {{.*}}>, memref<?x?xf32, {{.*}}>, memref<?x?xf32, {{.*}}>) -> ()
+  linalg.matmul ins(%A, %B: memref<?x?xf32>, memref<?x?xf32>)
+                outs(%C: memref<?x?xf32>)
+  return %C : memref<?x?xf32>
+}
+  


        


More information about the Mlir-commits mailing list