Skip to content

Commit e3ea2d7

Browse files
[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
1 parent c5028f3 commit e3ea2d7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: mlir-opt %s -convert-linalg-to-std | FileCheck %s
2+
3+
func private @print_memref_f32(memref<*xf32>)
4+
5+
// CHECK: func private @linalg_fill_f32_viewsxsxf32(f32, memref<?x?xf32, {{.*}}>) attributes {llvm.emit_c_interface}
6+
// CHECK: func private @linalg_matmul_viewsxsxf32_viewsxsxf32_viewsxsxf32(memref<?x?xf32, {{.*}}>, memref<?x?xf32, {{.*}}>, memref<?x?xf32, {{.*}}>) attributes {llvm.emit_c_interface}
7+
8+
func @matmul(%A: memref<?x?xf32>, %B: memref<?x?xf32>) -> (memref<?x?xf32>) {
9+
%c0 = constant 0 : index
10+
%c1 = constant 1 : index
11+
%f0 = constant 0.0 : f32
12+
%x = memref.dim %A, %c0 : memref<?x?xf32>
13+
%y = memref.dim %B, %c1 : memref<?x?xf32>
14+
%C = memref.alloc(%x, %y) : memref<?x?xf32>
15+
16+
// CHECK: call @linalg_fill_f32_viewsxsxf32({{.*}}) : (f32, memref<?x?xf32, {{.*}}>)
17+
linalg.fill(%f0, %C) : f32, memref<?x?xf32>
18+
19+
// CHECK: call @linalg_matmul_viewsxsxf32_viewsxsxf32_viewsxsxf32({{.*}}) : (memref<?x?xf32, {{.*}}>, memref<?x?xf32, {{.*}}>, memref<?x?xf32, {{.*}}>) -> ()
20+
linalg.matmul ins(%A, %B: memref<?x?xf32>, memref<?x?xf32>)
21+
outs(%C: memref<?x?xf32>)
22+
return %C : memref<?x?xf32>
23+
}
24+

0 commit comments

Comments
 (0)