Created
December 25, 2022 13:29
-
-
Save iwa0/0a898f47a4a2ad1fab19f0d450d0831c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mlir-opt matmult.mlir -convert-linalg-to-loops -lower-affine -convert-scf-to-cf -convert-linalg-to-llvm -convert-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts > out.mlir | |
mlir-cpu-runner out.mlir -O3 -e main -entry-point-result=void --shared-libs=libmlir_runner_utils.dylib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C += A * B. | |
func.func @matmul(%A: memref<2048x2048xf64>, %B: memref<2048x2048xf64>, %C: memref<2048x2048xf64>) { | |
affine.for %arg3 = 0 to 2048 { | |
affine.for %arg4 = 0 to 2048 { | |
affine.for %arg5 = 0 to 2048 { | |
%a = affine.load %A[%arg3, %arg5] : memref<2048x2048xf64> | |
%b = affine.load %B[%arg5, %arg4] : memref<2048x2048xf64> | |
%ci = affine.load %C[%arg3, %arg4] : memref<2048x2048xf64> | |
%p = arith.mulf %a, %b : f64 | |
%co = arith.addf %ci, %p : f64 | |
affine.store %co, %C[%arg3, %arg4] : memref<2048x2048xf64> | |
} | |
} | |
} | |
return | |
} | |
func.func @main() { | |
%A = memref.alloc() : memref<2048x2048xf64> | |
%B = memref.alloc() : memref<2048x2048xf64> | |
%C = memref.alloc() : memref<2048x2048xf64> | |
%cf1 = llvm.mlir.constant(1.00000e+00 : f64) : f64 | |
linalg.fill ins(%cf1 : f64) outs(%A : memref<2048x2048xf64>) | |
linalg.fill ins(%cf1 : f64) outs(%B : memref<2048x2048xf64>) | |
linalg.fill ins(%cf1 : f64) outs(%C : memref<2048x2048xf64>) | |
call @matmul(%A, %B, %C) : (memref<2048x2048xf64>, memref<2048x2048xf64>, memref<2048x2048xf64>) -> () | |
%C.cast = memref.cast %C : memref<2048x2048xf64> to memref<*xf64> | |
call @printMemrefF64(%C.cast): (memref<*xf64>) -> () | |
return | |
} | |
func.func private @printMemrefF64(memref<*xf64>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment