From faf419e57b6b9e8de686afa00dd15c97ac3ffe40 Mon Sep 17 00:00:00 2001 From: Artem Balyshev Date: Thu, 25 Apr 2024 13:52:55 +0300 Subject: [PATCH] add recipes and tests --- .../circle2circle-dredd-recipe-test/test.lst | 2 + compiler/luci-pass-value-test/test.lst | 2 + .../src/FuseMulWithFullyConnectedPass.cpp | 2 +- .../Net_FullyConnected_Mul_000/test.recipe | 66 ++++++++++++ .../Net_FullyConnected_Mul_000/test.rule | 6 ++ .../Net_StridedSlices_Neg_000/test.recipe | 102 ++++++++++++++++++ .../Net_StridedSlices_Neg_000/test.rule | 5 + 7 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 res/TensorFlowLiteRecipes/Net_FullyConnected_Mul_000/test.recipe create mode 100644 res/TensorFlowLiteRecipes/Net_FullyConnected_Mul_000/test.rule create mode 100644 res/TensorFlowLiteRecipes/Net_StridedSlices_Neg_000/test.recipe create mode 100644 res/TensorFlowLiteRecipes/Net_StridedSlices_Neg_000/test.rule diff --git a/compiler/circle2circle-dredd-recipe-test/test.lst b/compiler/circle2circle-dredd-recipe-test/test.lst index 0034571823b..b884dbb988f 100644 --- a/compiler/circle2circle-dredd-recipe-test/test.lst +++ b/compiler/circle2circle-dredd-recipe-test/test.lst @@ -64,6 +64,8 @@ Add(Net_Mul_Div_001 PASS fuse_mul_with_div) Add(Net_Preactivation_BN_000 PASS fuse_preactivation_batchnorm) Add(Net_Reshape_Reshape_000 PASS remove_redundant_reshape) Add(Net_Shape_Add_000 PASS fold_shape) +Add(Net_StriedSlices_Neg_000 PASS fuse_strided_slices_neg_as_mul_pattern) +Add(Net_FullyConnected_Mul_000 PASS fuse_mul_with_fully_connected) Add(Net_Squeeze_Squeeze_000 PASS substitute_squeeze_to_reshape) Add(Net_TConv_Add_000 PASS fuse_add_with_tconv) Add(Net_TConv_Add_001 PASS fuse_add_with_tconv) diff --git a/compiler/luci-pass-value-test/test.lst b/compiler/luci-pass-value-test/test.lst index d22464c610c..ad6944a665f 100644 --- a/compiler/luci-pass-value-test/test.lst +++ b/compiler/luci-pass-value-test/test.lst @@ -51,6 +51,8 @@ addeval(Net_InstanceNorm_001 fuse_instnorm) addeval(Net_InstanceNorm_002 fuse_instnorm) addeval(Net_InstanceNorm_003 fuse_instnorm) addeval(Net_StridedSlice_StridedSlice_000 remove_unnecessary_strided_slice) +addeval(Net_StriedSlices_Neg_000 fuse_strided_slices_neg_as_mul_pattern) +addeval(Net_FullyConnected_Mul_000 fuse_mul_with_fully_connected) addeval(FullyConnected_007 replace_non_const_fc_with_batch_matmul) addeval(Net_Transpose_Add_000 forward_transpose_op) addeval(Net_Transpose_Abs_000 forward_transpose_op) diff --git a/compiler/luci/pass/src/FuseMulWithFullyConnectedPass.cpp b/compiler/luci/pass/src/FuseMulWithFullyConnectedPass.cpp index a934a82728a..73aa2fce623 100644 --- a/compiler/luci/pass/src/FuseMulWithFullyConnectedPass.cpp +++ b/compiler/luci/pass/src/FuseMulWithFullyConnectedPass.cpp @@ -136,7 +136,7 @@ bool fuse_mul_with_fully_connected(luci::CircleMul *mul) // Configure new FullyConnected operation. auto *fused_fc = loco::must_cast(luci::clone_node(fc, mul->graph())); - fused_fc->input(fc->input()); + fused_fc->input(fc_input); fused_fc->weights(fused_fc_weight); if (fused_fc_bias != nullptr) { diff --git a/res/TensorFlowLiteRecipes/Net_FullyConnected_Mul_000/test.recipe b/res/TensorFlowLiteRecipes/Net_FullyConnected_Mul_000/test.recipe new file mode 100644 index 00000000000..db91e2dc336 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Net_FullyConnected_Mul_000/test.recipe @@ -0,0 +1,66 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 8 } +} +operand { + name: "mul_ifm" + type: FLOAT32 + shape { dim: 1 dim: 16 } + filler { + tag: "gaussian" + arg: "0.0" + arg: "1.0" + } +} +operand { + name: "fc_wgt" + type: FLOAT32 + shape { dim: 16 dim: 8 } + filler { + tag: "gaussian" + arg: "0.0" + arg: "1.0" + } +} +operand { + name: "fc_bias" + type: FLOAT32 + shape { dim: 16 } + filler { + tag: "gaussian" + arg: "0.0" + arg: "1.0" + } +} +operand { + name: "fc" + type: FLOAT32 + shape { dim: 1 dim: 16 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 16 } +} +operation { + type: "FullyConnected" + fullyconnected_options { + activation: NONE + } + input: "ifm" + input: "fc_wgt" + input: "fc_bias" + output: "fc" +} +operation { + type: "Mul" + input: "mul_ifm" + input: "fc" + output: "ofm" + mul_options { + activation: NONE + } +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Net_FullyConnected_Mul_000/test.rule b/res/TensorFlowLiteRecipes/Net_FullyConnected_Mul_000/test.rule new file mode 100644 index 00000000000..c18cf259cb3 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Net_FullyConnected_Mul_000/test.rule @@ -0,0 +1,6 @@ +# To check if Mul is fused + +RULE "VERIFY_FILE_FORMAT" $(verify_file_format) '=' 1 + +RULE "FC_EXIST" $(op_count FULLY_CONNECTED) '=' 1 +RULE "NO_MUL" $(op_count MUL) '=' 0 diff --git a/res/TensorFlowLiteRecipes/Net_StridedSlices_Neg_000/test.recipe b/res/TensorFlowLiteRecipes/Net_StridedSlices_Neg_000/test.recipe new file mode 100644 index 00000000000..c5ca0ad59ba --- /dev/null +++ b/res/TensorFlowLiteRecipes/Net_StridedSlices_Neg_000/test.recipe @@ -0,0 +1,102 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 1 dim: 4 } +} +operand { + name: "begin" + type: INT32 + shape { dim: 3 } + filler { tag: "explicit" arg: "0" arg: "0" arg: "0" } +} +operand { + name: "end" + type: INT32 + shape { dim: 3 } + filler { tag: "explicit" arg: "1" arg: "1" arg: "2" } +} +operand { + name: "strides" + type: INT32 + shape { dim: 3 } + filler { tag: "explicit" arg: "1" arg: "1" arg: "1" } +} +operand { + name: "output_1" + type: FLOAT32 + shape { dim: 1 dim: 1 dim: 2 } +} +operation { + type: "StridedSlice" + strided_slice_options { + begin_mask: 0 + end_mask: 0 + ellipsis_mask: 0 + new_axis_mask: 0 + shrink_axis_mask: 0 + } + input: "ifm" + input: "begin" + input: "end" + input: "strides" + output: "output_1" +} +operand { + name: "begin_2" + type: INT32 + shape { dim: 3 } + filler { tag: "explicit" arg: "0" arg: "0" arg: "2" } +} +operand { + name: "end_2" + type: INT32 + shape { dim: 3 } + filler { tag: "explicit" arg: "1" arg: "1" arg: "4" } +} +operand { + name: "output_2" + type: FLOAT32 + shape { dim: 1 dim:1 dim: 2 } +} +operation { + type: "StridedSlice" + strided_slice_options { + begin_mask: 0 + end_mask: 0 + ellipsis_mask: 0 + new_axis_mask: 0 + shrink_axis_mask: 0 + } + input: "ifm" + input: "begin_2" + input: "end_2" + input: "strides" + output: "output_2" +} +operand { + name: "output_neg" + type: FLOAT32 + shape { dim: 1 dim: 1 dim: 2 } +} +operation { + type: "Neg" + input: "output_2" + output: "output_neg" +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 1 dim: 4 } +} +operation { + type: "Concatenation" + concatenation_options { + axis: -1 + activation: NONE + } + input: "output_1" + input: "output_neg" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/res/TensorFlowLiteRecipes/Net_StridedSlices_Neg_000/test.rule b/res/TensorFlowLiteRecipes/Net_StridedSlices_Neg_000/test.rule new file mode 100644 index 00000000000..7d1421094e3 --- /dev/null +++ b/res/TensorFlowLiteRecipes/Net_StridedSlices_Neg_000/test.rule @@ -0,0 +1,5 @@ +# To check if StridedSlicesNeg pattern fused as mul. + +RULE "VERIFY_FILE_FORMAT" $(verify_file_format) '=' 1 +RULE "MUL_EXIST" $(op_count MUL) '=' 1 +RULE "NO_STRIDEDSLICES" $(op_count STRIDEDSLICE) '=' 0