-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Squat Packing's rotate and sum operation and resolved type mism…
…atch issues. PiperOrigin-RevId: 674752765
- Loading branch information
1 parent
91b00ef
commit 426bfe7
Showing
10 changed files
with
412 additions
and
147 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
338 changes: 238 additions & 100 deletions
338
lib/Conversion/LinalgToTensorExt/LinalgToTensorExt.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
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,45 @@ | ||
// RUN: heir-opt %s --linalg-to-tensor-ext=tiling-size=4 --tosa-to-secret-arith --canonicalize | FileCheck %s | ||
|
||
// TODO: Fix Test | ||
|
||
// CHECK: func.func @test_float_small_fc_network(%[[ARG:.*]]: !secret.secret<tensor<1x4xf32>>) | ||
module { | ||
func.func @test_float_small_fc_network(%input : !secret.secret<tensor<1x1xf32>>) -> !secret.secret<tensor<1x1xf32>> { | ||
%matrix1 = arith.constant dense<[[1.0, 2.0, 3.0, 4.0]]> : tensor<1x4xf32> | ||
%bias1 = arith.constant dense<[[5.0, 6.0, 7.0, 8.0]]> : tensor<1x4xf32> | ||
%layer1 = secret.generic ins (%input : !secret.secret<tensor<1x1xf32>>) { | ||
^bb0(%converted_input1: tensor<1x1xf32>): | ||
%0 = linalg.matmul ins(%converted_input1, %matrix1 : tensor<1x1xf32>, tensor<1x4xf32>) outs(%bias1 : tensor<1x4xf32>) -> tensor<1x4xf32> | ||
secret.yield %0 : tensor<1x4xf32> | ||
} -> !secret.secret<tensor<1x4xf32>> | ||
|
||
%activation_layer1 = secret.generic ins (%layer1 : !secret.secret<tensor<1x4xf32>>) { | ||
^bb0(%converted_activation_layer_vec1: tensor<1x4xf32>): | ||
%0 = tosa.sigmoid %converted_activation_layer_vec1 : (tensor<1x4xf32>) -> tensor<1x4xf32> | ||
secret.yield %0 : tensor<1x4xf32> | ||
} -> !secret.secret<tensor<1x4xf32>> | ||
|
||
%matrix2 = arith.constant dense<[[10.0, 20.0, 30.0, 40.0], [50.0, 60.0, 70.0, 80.0], [90.0, 100.0, 110.0, 120.0], [130.0, 140.0, 150.0, 160.0]]> : tensor<4x4xf32> | ||
%bias2 = arith.constant dense<[[170.0, 180.0, 190.0, 200.0]]> : tensor<1x4xf32> | ||
%layer2 = secret.generic ins (%layer1 : !secret.secret<tensor<1x4xf32>>) { | ||
^bb0(%converted_vec2: tensor<1x4xf32>): | ||
%1 = linalg.matmul ins(%converted_vec2, %matrix2 : tensor<1x4xf32>, tensor<4x4xf32>) outs(%bias2 : tensor<1x4xf32>) -> tensor<1x4xf32> | ||
secret.yield %1 : tensor<1x4xf32> | ||
} -> !secret.secret<tensor<1x4xf32>> | ||
|
||
%activation_layer2 = secret.generic ins (%layer2 : !secret.secret<tensor<1x4xf32>>) { | ||
^bb0(%converted_activation_layer_vec2: tensor<1x4xf32>): | ||
%0 = tosa.sigmoid %converted_activation_layer_vec2 : (tensor<1x4xf32>) -> tensor<1x4xf32> | ||
secret.yield %0 : tensor<1x4xf32> | ||
} -> !secret.secret<tensor<1x4xf32>> | ||
|
||
%matrix3 = arith.constant dense<[[100.0], [200.0], [300.0], [400.0]]> : tensor<4x1xf32> | ||
%bias3 = arith.constant dense<[[500.0]]> : tensor<1x1xf32> | ||
%layer3 = secret.generic ins (%activation_layer2 : !secret.secret<tensor<1x4xf32>>) { | ||
^bb0(%converted_vec3: tensor<1x4xf32>): | ||
%0 = linalg.matmul ins(%converted_vec3, %matrix3 : tensor<1x4xf32>, tensor<4x1xf32>) outs(%bias3 : tensor<1x1xf32>) -> tensor<1x1xf32> | ||
secret.yield %0 : tensor<1x1xf32> | ||
} -> !secret.secret<tensor<1x1xf32>> | ||
return %layer3 : !secret.secret<tensor<1x1xf32>> | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/linalg_to_tensor_ext/float_vector_small_matrix_matmul.mlir
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,17 @@ | ||
// RUN: heir-opt %s --linalg-to-tensor-ext=tiling-size=4 --canonicalize | FileCheck %s | ||
|
||
// TODO: Fix Test | ||
|
||
// CHECK: func.func @test_float_vector_small_matrix_matmul(%[[ARG:.*]]: !secret.secret<tensor<1x4xf32>>) | ||
module { | ||
func.func @test_float_vector_small_matrix_matmul(%vec : !secret.secret<tensor<1x4xf32>>) -> !secret.secret<tensor<1x1xf32>> { | ||
%matrix = arith.constant dense<[[1.0], [2.0], [3.0], [4.0]]> : tensor<4x1xf32> | ||
%bias = arith.constant dense<[[5.0]]> : tensor<1x1xf32> | ||
%out = secret.generic ins (%vec : !secret.secret<tensor<1x4xf32>>) { | ||
^bb0(%converted_vec: tensor<1x4xf32>): | ||
%0 = linalg.matmul ins(%converted_vec, %matrix : tensor<1x4xf32>, tensor<4x1xf32>) outs(%bias : tensor<1x1xf32>) -> tensor<1x1xf32> | ||
secret.yield %0 : tensor<1x1xf32> | ||
} -> !secret.secret<tensor<1x1xf32>> | ||
return %out : !secret.secret<tensor<1x1xf32>> | ||
} | ||
} |
38 changes: 19 additions & 19 deletions
38
tests/linalg_to_tensor_ext/float_vector_square_matrix_matmul_op.mlir
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
36 changes: 36 additions & 0 deletions
36
tests/linalg_to_tensor_ext/integer_rect_matrix_vector_matmul_op.mlir
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,36 @@ | ||
// RUN: heir-opt %s --linalg-to-tensor-ext=tiling-size=4 --canonicalize | FileCheck %s | ||
|
||
// CHECK: func.func @test_integer_rect_matrix_vector_matmul(%[[ARG:.*]]: !secret.secret<tensor<4x1xi16>>) | ||
// CHECK-DAG: %[[ONE:.*]] = arith.constant 1 : index | ||
// CHECK-DAG: %[[TWO:.*]] = arith.constant 2 : index | ||
// CHECK-DAG: %[[BIAS:.*]] = arith.constant dense | ||
// CHECK-SAME{LITERAL}: <[[17], [18], [17], [18]]> : tensor<4x1xi16> | ||
// CHECK-DAG: %[[DIAGONALIZED_MATRIX:.*]] = arith.constant dense | ||
// CHECK-SAME{LITERAL}: <[[1, 2, 3, 4], [6, 7, 8, 5], [3, 4, 1, 2], [8, 5, 6, 7]]> : tensor<4x4xi16> | ||
// CHECK-DAG: %[[LAST_SLICE:.*]] = tensor.extract_slice %[[DIAGONALIZED_MATRIX]][0, 1] [4, 1] [1, 1] | ||
// CHECK: %[[OUT:.*]] = secret.generic ins(%[[ARG]] : !secret.secret<tensor<4x1xi16>>) | ||
// CHECK: ^bb0(%[[ARG_CONVERTED:.*]]: tensor<4x1xi16>): | ||
// CHECK: %[[FOR_LOOP_OUT:.*]]:2 = affine.for %[[I:.*]] = 0 to 1 iter_args(%[[RUNNING_SUM:.*]] = %[[BIAS]], %[[ROTATED_VEC:.*]] = %[[ARG_CONVERTED]]) | ||
// CHECK: %[[SLICE:.*]] = tensor.extract_slice %[[DIAGONALIZED_MATRIX]][0, %[[I]]] [4, 1] [1, 1] | ||
// CHECK: %[[MUL:.*]] = arith.muli %[[ROTATED_VEC]], %[[SLICE]] | ||
// CHECK: %[[UPDATED_SUM:.*]] = arith.addi %[[RUNNING_SUM]], %[[MUL]] | ||
// CHECK: %[[UPDATED_ROTATED_VEC:.*]] = tensor_ext.rotate %[[ROTATED_VEC]], %[[ONE]] | ||
// CHECK: affine.yield %[[UPDATED_SUM]], %[[UPDATED_ROTATED_VEC]] | ||
// CHECK: %[[LAST_MUL:.*]] = arith.muli %[[FOR_LOOP_OUT]]#1, %[[LAST_SLICE]] | ||
// CHECK: %[[BEFORE_ROTATE_AND_SUM:.*]] = arith.addi %[[FOR_LOOP_OUT]]#0, %[[LAST_MUL]] | ||
// CHECK: %[[ROTATED_SUM:.*]] = tensor_ext.rotate %[[BEFORE_ROTATE_AND_SUM]], %[[TWO]] | ||
// CHECK: %[[FINAL_SUM:.*]] = arith.addi %[[BEFORE_ROTATE_AND_SUM]], %[[ROTATED_SUM]] | ||
// CHECK: secret.yield %[[FINAL_SUM]] | ||
// CHECK: return %[[OUT]] | ||
module { | ||
func.func @test_integer_rect_matrix_vector_matmul(%vec : !secret.secret<tensor<4x1xi16>>) -> !secret.secret<tensor<2x1xi16>> { | ||
%matrix = arith.constant dense<[[1, 2, 3, 4], [5, 6, 7, 8]]> : tensor<2x4xi16> | ||
%bias = arith.constant dense<[[17], [18]]> : tensor<2x1xi16> | ||
%out = secret.generic ins (%vec : !secret.secret<tensor<4x1xi16>>) { | ||
^bb0(%converted_vec: tensor<4x1xi16>): | ||
%0 = linalg.matmul ins(%matrix, %converted_vec : tensor<2x4xi16>, tensor<4x1xi16>) outs(%bias : tensor<2x1xi16>) -> tensor<2x1xi16> | ||
secret.yield %0 : tensor<2x1xi16> | ||
} -> !secret.secret<tensor<2x1xi16>> | ||
return %out : !secret.secret<tensor<2x1xi16>> | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/linalg_to_tensor_ext/integer_small_vector_matrix_matmul_op.mlir
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,17 @@ | ||
// RUN: heir-opt %s --linalg-to-tensor-ext=tiling-size=4 --canonicalize | FileCheck %s | ||
|
||
// TODO: Fix Test | ||
|
||
// CHECK: func.func @test_integer_small_vector_rect_matrix_matmul(%[[ARG:.*]]: !secret.secret<tensor<1x4xi16>>) | ||
module { | ||
func.func @test_integer_small_vector_rect_matrix_matmul(%vec : !secret.secret<tensor<1x1xi16>>) -> !secret.secret<tensor<1x4xi16>> { | ||
%matrix = arith.constant dense<[[1, 2, 3, 4]]> : tensor<1x4xi16> | ||
%bias = arith.constant dense<[[5, 6, 7, 8]]> : tensor<1x4xi16> | ||
%out = secret.generic ins (%vec : !secret.secret<tensor<1x1xi16>>) { | ||
^bb0(%converted_vec: tensor<1x1xi16>): | ||
%0 = linalg.matmul ins(%converted_vec, %matrix : tensor<1x1xi16>, tensor<1x4xi16>) outs(%bias : tensor<1x4xi16>) -> tensor<1x4xi16> | ||
secret.yield %0 : tensor<1x4xi16> | ||
} -> !secret.secret<tensor<1x4xi16>> | ||
return %out : !secret.secret<tensor<1x4xi16>> | ||
} | ||
} |
18 changes: 9 additions & 9 deletions
18
tests/linalg_to_tensor_ext/integer_square_matrix_vector_matmul_op.mlir
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
38 changes: 19 additions & 19 deletions
38
tests/linalg_to_tensor_ext/integer_vector_square_matrix_matmul_op.mlir
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