-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[midend][examples] Add MatMulParallelVectorization, BuiltinTransposeV…
…ectorization, BatchMatMulOptimize. (#215) * [midend] Add MatMulParallelVectorization and optimized BatchMatMulOptimize. * [examples] Fix makefile arguments and add MatMulParallelVectorization testcase. * [midend][examples] Add parallelize BuiltinTransposeVectorization and tests. * [midend] Restrict the transpose optimize for 2 rank tensor and remove unused header files. * [midend] Canonicalize dynamic rank detection.
- Loading branch information
1 parent
4cee632
commit 719e7de
Showing
14 changed files
with
1,340 additions
and
186 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: buddy-opt -matmul-paralell-vectorization-optimize -verify-diagnostics -expand-strided-metadata -lower-affine -convert-vector-to-llvm -finalize-memref-to-llvm -convert-scf-to-cf -convert-linalg-to-llvm -llvm-request-c-wrappers -convert-func-to-llvm -reconcile-unrealized-casts %s \ | ||
// RUN: | mlir-cpu-runner -O0 -e buddy_matmul_f32 -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 | ||
|
||
memref.global "private" @A : memref<4x3xf32> = dense<[[9., 4., 6.],[2., 4., 0.],[6., 3., 3.],[0., 4., 7.]]> | ||
memref.global "private" @B : memref<3x4xf32> = dense<[[1., 3., 8., 0.],[1., 8., 8., 7.], [6., 9., 7., 9.]]> | ||
memref.global "private" @C : memref<4x4xf32> = dense<[[49., 113., 146., 82.],[6., 38., 48., 28.],[24., 81., 36., 78.],[8., 56., 0., 52.]]> | ||
|
||
func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface } | ||
|
||
func.func @buddy_matmul_f32(){ | ||
%a = memref.get_global @A : memref<4x3xf32> | ||
%b = memref.get_global @B : memref<3x4xf32> | ||
%c = memref.get_global @C : memref<4x4xf32> | ||
|
||
linalg.matmul | ||
ins(%a, %b: memref<4x3xf32>, memref<3x4xf32>) | ||
outs(%c: memref<4x4xf32>) | ||
%printed_c = memref.cast %c : memref<4x4xf32> to memref<*xf32> | ||
call @printMemrefF32(%printed_c) : (memref<*xf32>) -> () | ||
// CHECK: {{Unranked Memref base@ = 0x[0-9A-Fa-f]{1,} rank = 2 offset = 0 sizes = \[4, 4\] strides = \[4, 1\] data =}} | ||
// CHECK{LITERAL}: [[98, 226, 292, 164], | ||
// CHECK{LITERAL}: [12, 76, 96, 56], | ||
// CHECK{LITERAL}: [51, 150, 129, 126], | ||
// CHECK{LITERAL}: [54, 151, 81, 143]] | ||
return | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// RUN: buddy-opt -matmul-paralell-vectorization-optimize -verify-diagnostics -expand-strided-metadata -lower-affine -convert-vector-to-llvm -finalize-memref-to-llvm -convert-scf-to-cf -convert-linalg-to-llvm -llvm-request-c-wrappers -convert-func-to-llvm -reconcile-unrealized-casts %s \ | ||
// RUN: | mlir-cpu-runner -O0 -e buddy_matmul_i8 -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 | ||
|
||
memref.global "private" @A : memref<4x3xi8> = dense<[[9, 4, 6],[2, 4, 0],[6, 3, 3],[0, 4, 7]]> | ||
memref.global "private" @B : memref<3x4xi8> = dense<[[1, 3, 8, 0],[1, 8, 8, 7], [6, 9, 7, 9]]> | ||
memref.global "private" @C : memref<4x4xi8> = dense<[[49, 113, 46, 82],[6, 38, 48, 28],[24, 81, 36, 78],[8, 56, 0, 52]]> | ||
|
||
func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface } | ||
|
||
func.func @buddy_matmul_i8(){ | ||
%a = memref.get_global @A : memref<4x3xi8> | ||
%b = memref.get_global @B : memref<3x4xi8> | ||
%c = memref.get_global @C : memref<4x4xi8> | ||
|
||
linalg.matmul | ||
ins(%a, %b: memref<4x3xi8>, memref<3x4xi8>) | ||
outs(%c: memref<4x4xi8>) | ||
|
||
%cst_0 = arith.constant 0 : index | ||
%cst_1 = arith.constant 1 : index | ||
%cst_4 = arith.constant 4 : index | ||
|
||
%c_f32 = memref.alloca() : memref<4x4xf32> | ||
scf.for %i = %cst_0 to %cst_4 step %cst_1 { | ||
scf.for %j = %cst_0 to %cst_4 step %cst_1 { | ||
%val_i8 = memref.load %c[%i, %j] : memref<4x4xi8> | ||
%val_f32 = arith.sitofp %val_i8 : i8 to f32 | ||
memref.store %val_f32, %c_f32[%i, %j] : memref<4x4xf32> | ||
} | ||
} | ||
|
||
%printed_c = memref.cast %c_f32 : memref<4x4xf32> to memref<*xf32> | ||
call @printMemrefF32(%printed_c) : (memref<*xf32>) -> () | ||
// CHECK: {{Unranked Memref base@ = 0x[0-9A-Fa-f]{1,} rank = 2 offset = 0 sizes = \[4, 4\] strides = \[4, 1\] data =}} | ||
// CHECK{LITERAL}: [[98, -30, -64, -92], | ||
// CHECK{LITERAL}: [12, 76, 96, 56], | ||
// CHECK{LITERAL}: [51, -106, -127, 126], | ||
// CHECK{LITERAL}: [54, -105, 81, -113]] | ||
return | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: buddy-opt -transpose-optimize="vector-size=16" -verify-diagnostics -lower-affine -expand-strided-metadata -convert-vector-to-scf -convert-vector-to-llvm -finalize-memref-to-llvm -convert-scf-to-cf -convert-arith-to-llvm -convert-func-to-llvm -lower-affine -llvm-request-c-wrappers -convert-arith-to-llvm -reconcile-unrealized-casts %s \ | ||
// RUN: | mlir-cpu-runner -O0 -e buddy_transpose_f32 -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 | ||
|
||
memref.global "private" @A : memref<3x4xf32> = dense<[[1., 3., 8., 0.],[1., 8., 8., 7.], [6., 9., 7., 9.]]> | ||
|
||
func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface } | ||
|
||
func.func @buddy_transpose_f32(){ | ||
%a = memref.get_global @A : memref<3x4xf32> | ||
%b = memref.alloc() : memref<4x3xf32> | ||
|
||
linalg.transpose | ||
ins(%a: memref<3x4xf32>) | ||
outs(%b: memref<4x3xf32>) | ||
permutation = [1, 0] | ||
%printed_b = memref.cast %b : memref<4x3xf32> to memref<*xf32> | ||
call @printMemrefF32(%printed_b) : (memref<*xf32>) -> () | ||
memref.dealloc %b : memref<4x3xf32> | ||
// CHECK: {{Unranked Memref base@ = 0x[0-9A-Fa-f]{1,} rank = 2 offset = 0 sizes = \[4, 3\] strides = \[3, 1\] data =}} | ||
// CHECK{LITERAL}: [[1, 1, 6], | ||
// CHECK{LITERAL}: [3, 8, 9], | ||
// CHECK{LITERAL}: [8, 8, 7], | ||
// CHECK{LITERAL}: [0, 7, 9]] | ||
return | ||
} |
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
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
Oops, something went wrong.