forked from buddy-compiler/buddy-mlir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DIP] Infer operation data type based on its params for Corr2D (buddy…
…-compiler#63) * Add lit-test for correlation2D * Add correlation i32 test * Add support for i32 correlation 2d * Enable default attribute printing for DIP * Add a check for compatbility return type * Update lit test to find mlir cpu utils * Make output to be param for Corr2d - having it as a return value causes to segfault correlation2D sample - it is not clear how to return MemRef from C-interface * Mark attributes with <> in dip.mlir * Add a operand type check for Corr2D op and a test - Make sure that input, kernel, output and constant have the same value and use as inferred type - Adding a negative lit test to check params of the op * Fix review comments * Add support for i8,i64,f64 * Fix correlation2D_f64 test * by constructing F64 correctly * Fix review comment and formatting issues * Fix more review comment - extend correlation2d_invalid_type test to cover a condition for supported types - add comments for utility functions * Remove insertZeroConstantOp from LowerDIPPass - it is present in DIPItility.h * Trivial changes Co-authored-by: meshtag <prathameshtagore@gmail.com>
- Loading branch information
1 parent
a42d012
commit 39b1b78
Showing
13 changed files
with
388 additions
and
32 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
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,42 @@ | ||
// | ||
// x86 | ||
// | ||
// RUN: buddy-opt %s -lower-dip="DIP-strip-mining=64" -arith-expand --convert-vector-to-scf --lower-affine --convert-scf-to-cf --convert-vector-to-llvm \ | ||
// RUN: --convert-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts \ | ||
// RUN: | mlir-cpu-runner -O0 -e main -entry-point-result=i32 \ | ||
// 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" @global_input : memref<3x3xf32> = dense<[[0. , 1. , 2. ], | ||
[10., 11., 12.], | ||
[20., 21., 22.]]> | ||
|
||
memref.global "private" @global_identity : memref<3x3xf32> = dense<[[0., 0., 0.], | ||
[0., 1., 0.], | ||
[0., 0., 0.]]> | ||
|
||
memref.global "private" @global_output : memref<3x3xf32> = dense<[[0., 0., 0.], | ||
[0., 0., 0.], | ||
[0., 0., 0.]]> | ||
func.func private @printMemrefF32(memref<*xf32>) attributes { llvm.emit_c_interface } | ||
|
||
func.func @main() -> i32 { | ||
%input = memref.get_global @global_input : memref<3x3xf32> | ||
%identity = memref.get_global @global_identity : memref<3x3xf32> | ||
%output = memref.get_global @global_output : memref<3x3xf32> | ||
|
||
%kernelAnchorX = arith.constant 1 : index | ||
%kernelAnchorY = arith.constant 1 : index | ||
%c = arith.constant 0. : f32 | ||
dip.corr_2d <CONSTANT_PADDING> %input, %identity, %output, %kernelAnchorX, %kernelAnchorY, %c : memref<3x3xf32>, memref<3x3xf32>, memref<3x3xf32>, index, index, f32 | ||
|
||
%printed_output = memref.cast %output : memref<3x3xf32> to memref<*xf32> | ||
call @printMemrefF32(%printed_output) : (memref<*xf32>) -> () | ||
// CHECK: {{Unranked Memref base@ = 0x[0-9A-Fa-f]{1,} rank = 2 offset = 0 sizes = \[3, 3\] strides = \[3, 1\] data =}} | ||
// CHECK{LITERAL}: [[0, 1, 2], | ||
// CHECK{LITERAL}: [10, 11, 12], | ||
// CHECK{LITERAL}: [20, 21, 22]] | ||
|
||
%ret = arith.constant 0 : i32 | ||
return %ret : i32 | ||
} |
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 @@ | ||
// | ||
// x86 | ||
// | ||
// RUN: buddy-opt %s -lower-dip="DIP-strip-mining=64" -arith-expand --convert-vector-to-scf --lower-affine --convert-scf-to-cf --convert-vector-to-llvm \ | ||
// RUN: --convert-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts \ | ||
// RUN: | mlir-cpu-runner -O0 -e main -entry-point-result=i32 \ | ||
// 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" @global_input : memref<3x3xf64> = dense<[[0. , 1. , 2. ], | ||
[10., 11., 12.], | ||
[20., 21., 22.]]> | ||
|
||
memref.global "private" @global_identity : memref<3x3xf64> = dense<[[0., 0., 0.], | ||
[0., 1., 0.], | ||
[0., 0., 0.]]> | ||
|
||
memref.global "private" @global_output : memref<3x3xf64> = dense<[[0., 0., 0.], | ||
[0., 0., 0.], | ||
[0., 0., 0.]]> | ||
func.func private @printMemrefF64(memref<*xf64>) attributes { llvm.emit_c_interface } | ||
|
||
func.func @main() -> i32 { | ||
%input = memref.get_global @global_input : memref<3x3xf64> | ||
%identity = memref.get_global @global_identity : memref<3x3xf64> | ||
%output = memref.get_global @global_output : memref<3x3xf64> | ||
|
||
%kernelAnchorX = arith.constant 1 : index | ||
%kernelAnchorY = arith.constant 1 : index | ||
%c = arith.constant 0. : f64 | ||
dip.corr_2d <CONSTANT_PADDING> %input, %identity, %output, %kernelAnchorX, %kernelAnchorY, %c : memref<3x3xf64>, memref<3x3xf64>, memref<3x3xf64>, index, index, f64 | ||
|
||
%printed_output = memref.cast %output : memref<3x3xf64> to memref<*xf64> | ||
call @printMemrefF64(%printed_output) : (memref<*xf64>) -> () | ||
// CHECK: {{Unranked Memref base@ = 0x[0-9A-Fa-f]{1,} rank = 2 offset = 0 sizes = \[3, 3\] strides = \[3, 1\] data =}} | ||
// CHECK{LITERAL}: [[0, 1, 2], | ||
// CHECK{LITERAL}: [10, 11, 12], | ||
// CHECK{LITERAL}: [20, 21, 22]] | ||
|
||
%ret = arith.constant 0 : i32 | ||
return %ret : i32 | ||
} |
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,41 @@ | ||
// | ||
// x86 | ||
// | ||
// RUN: buddy-opt %s -lower-dip="DIP-strip-mining=64" -arith-expand --convert-vector-to-scf --lower-affine --convert-scf-to-cf --convert-vector-to-llvm \ | ||
// RUN: --convert-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts \ | ||
// RUN: | mlir-cpu-runner -O0 -e main -entry-point-result=i32 \ | ||
// 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" @global_input : memref<3x3xi32> = dense<[[0 , 1 , 2 ], | ||
[10, 11, 12], | ||
[20, 21, 22]]> | ||
|
||
memref.global "private" @global_identity : memref<3x3xi32> = dense<[[0, 0, 0], | ||
[0, 1, 0], | ||
[0, 0, 0]]> | ||
|
||
memref.global "private" @global_output : memref<3x3xi32> = dense<[[0, 0, 0], | ||
[0, 0, 0], | ||
[0, 0, 0]]> | ||
func.func private @printMemrefI32(memref<*xi32>) attributes { llvm.emit_c_interface } | ||
|
||
func.func @main() -> i32 { | ||
%input = memref.get_global @global_input : memref<3x3xi32> | ||
%identity = memref.get_global @global_identity : memref<3x3xi32> | ||
%output = memref.get_global @global_output: memref<3x3xi32> | ||
|
||
%kernelAnchorX = arith.constant 1 : index | ||
%kernelAnchorY = arith.constant 1 : index | ||
%c = arith.constant 0 : i32 | ||
dip.corr_2d <CONSTANT_PADDING> %input, %identity, %output, %kernelAnchorX, %kernelAnchorY, %c : memref<3x3xi32>, memref<3x3xi32>, memref<3x3xi32>, index, index, i32 | ||
|
||
%printed_output = memref.cast %output : memref<3x3xi32> to memref<*xi32> | ||
call @printMemrefI32(%printed_output) : (memref<*xi32>) -> () | ||
// CHECK: {{Unranked Memref base@ = 0x[0-9A-Fa-f]{1,} rank = 2 offset = 0 sizes = \[3, 3\] strides = \[3, 1\] data =}} | ||
// CHECK{LITERAL}: [[0, 1, 2], | ||
// CHECK{LITERAL}: [10, 11, 12], | ||
// CHECK{LITERAL}: [20, 21, 22]] | ||
%ret = arith.constant 0 : i32 | ||
return %ret : i32 | ||
} |
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 @@ | ||
// | ||
// x86 | ||
// | ||
// RUN: buddy-opt %s -lower-dip="DIP-strip-mining=64" -arith-expand --convert-vector-to-scf --lower-affine --convert-scf-to-cf --convert-vector-to-llvm \ | ||
// RUN: --convert-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts \ | ||
// RUN: | mlir-cpu-runner -O0 -e main -entry-point-result=i32 \ | ||
// 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" @global_input : memref<3x3xi64> = dense<[[0 , 1 , 2 ], | ||
[10, 11, 12], | ||
[20, 21, 22]]> | ||
|
||
memref.global "private" @global_identity : memref<3x3xi64> = dense<[[0, 0, 0], | ||
[0, 1, 0], | ||
[0, 0, 0]]> | ||
|
||
memref.global "private" @global_output : memref<3x3xi64> = dense<[[0, 0, 0], | ||
[0, 0, 0], | ||
[0, 0, 0]]> | ||
|
||
func.func private @printMemrefI64(memref<*xi64>) attributes { llvm.emit_c_interface } | ||
|
||
func.func @main() -> i32 { | ||
%input = memref.get_global @global_input : memref<3x3xi64> | ||
%identity = memref.get_global @global_identity : memref<3x3xi64> | ||
%output = memref.get_global @global_output: memref<3x3xi64> | ||
|
||
%kernelAnchorX = arith.constant 1 : index | ||
%kernelAnchorY = arith.constant 1 : index | ||
%c = arith.constant 0 : i64 | ||
dip.corr_2d <CONSTANT_PADDING> %input, %identity, %output, %kernelAnchorX, %kernelAnchorY, %c : memref<3x3xi64>, memref<3x3xi64>, memref<3x3xi64>, index, index, i64 | ||
|
||
%printed_output = memref.cast %output : memref<3x3xi64> to memref<*xi64> | ||
call @printMemrefI64(%printed_output) : (memref<*xi64>) -> () | ||
// CHECK: {{Unranked Memref base@ = 0x[0-9A-Fa-f]{1,} rank = 2 offset = 0 sizes = \[3, 3\] strides = \[3, 1\] data =}} | ||
// CHECK{LITERAL}: [[0, 1, 2], | ||
// CHECK{LITERAL}: [10, 11, 12], | ||
// CHECK{LITERAL}: [20, 21, 22]] | ||
%ret = arith.constant 0 : i32 | ||
return %ret : i32 | ||
} |
Oops, something went wrong.