From c8c711223df24c4d132a1eedaa3182195a279685 Mon Sep 17 00:00:00 2001 From: bokyeong lee Date: Wed, 28 Aug 2024 16:55:02 +0900 Subject: [PATCH 1/3] [luci/service] Migrate Quantize shape inference rule to sinf::Algorithm This commit Migrate Quantize shape inference rule to sinf::Algorithm. ONE-DCO-1.0-Signed-off-by: kyeong8139 --- .../luci/Service/CircleShapeInference.h | 2 +- .../service/src/CircleShapeInferenceRule.cpp | 6 --- .../luci/service/src/Nodes/CircleQuantize.cpp | 9 ++++ .../service/src/Nodes/CircleQuantize.test.cpp | 46 +++++++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/compiler/luci/service/include/luci/Service/CircleShapeInference.h b/compiler/luci/service/include/luci/Service/CircleShapeInference.h index 88ce7d639ba..3406f63a57f 100644 --- a/compiler/luci/service/include/luci/Service/CircleShapeInference.h +++ b/compiler/luci/service/include/luci/Service/CircleShapeInference.h @@ -111,7 +111,7 @@ class Algorithm final : public luci::CircleNodeVisitor // loco::TensorShape visit(const luci::CirclePadV2 *node) final; // loco::TensorShape visit(const luci::CirclePow *node) final; // loco::TensorShape visit(const luci::CirclePRelu *node) final; - // loco::TensorShape visit(const luci::CircleQuantize *node) final; + loco::TensorShape visit(const luci::CircleQuantize *node) final; // loco::TensorShape visit(const luci::CircleRange *node) final; // loco::TensorShape visit(const luci::CircleRank *node) final; // loco::TensorShape visit(const luci::CircleReduceAny *node) final; diff --git a/compiler/luci/service/src/CircleShapeInferenceRule.cpp b/compiler/luci/service/src/CircleShapeInferenceRule.cpp index 32911feaa16..e01248b71fd 100644 --- a/compiler/luci/service/src/CircleShapeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleShapeInferenceRule.cpp @@ -2235,12 +2235,6 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitorinput()).as(); - return loco::NodeShape{input_shape}; - } - loco::NodeShape visit(const luci::CircleRange *node) final { return infer_range(node); } loco::NodeShape visit(const luci::CircleRank *) final diff --git a/compiler/luci/service/src/Nodes/CircleQuantize.cpp b/compiler/luci/service/src/Nodes/CircleQuantize.cpp index a78eb3f0284..85070f11bd8 100644 --- a/compiler/luci/service/src/Nodes/CircleQuantize.cpp +++ b/compiler/luci/service/src/Nodes/CircleQuantize.cpp @@ -14,7 +14,10 @@ * limitations under the License. */ +#include "luci/Service/CircleShapeInference.h" + #include "CircleCloneNode.h" +#include "CircleShapeInferenceHelper.h" namespace luci { @@ -24,4 +27,10 @@ luci::CircleNode *CloneNodeLet::visit(const luci::CircleQuantize *) return _graph->nodes()->create(); } +loco::TensorShape sinf::Algorithm::visit(const luci::CircleQuantize *node) +{ + const auto input_shape = sinf::circle_shape(loco::must_cast(node->input())); + return input_shape; +} + } // namespace luci diff --git a/compiler/luci/service/src/Nodes/CircleQuantize.test.cpp b/compiler/luci/service/src/Nodes/CircleQuantize.test.cpp index 628dfa1e647..9cfa9ed8dbf 100644 --- a/compiler/luci/service/src/Nodes/CircleQuantize.test.cpp +++ b/compiler/luci/service/src/Nodes/CircleQuantize.test.cpp @@ -15,6 +15,7 @@ */ #include "luci/Service/CircleNodeClone.h" +#include "luci/Service/CircleShapeInference.h" #include @@ -31,3 +32,48 @@ TEST(CloneNodeTest, clone_Quantize) auto cloned_q = dynamic_cast(cloned); ASSERT_NE(nullptr, cloned_q); } + +TEST(ShapeRuleTest, quantize_dynamic_shape) +{ + luci::CircleQuantize quantize; + luci::CircleInput input; + + input.shape({1, 2, 3, 4}); + input.shape_status(luci::ShapeStatus::VALID); + input.dim(2).unset(); + + quantize.input(&input); + + loco::TensorShape shape; + luci::sinf::Rule shape_inf_rule; + + ASSERT_TRUE(shape_inf_rule.infer(&quantize, shape)); + + ASSERT_EQ(4, shape.rank()); + ASSERT_TRUE(shape.dim(0).known()); + ASSERT_TRUE(shape.dim(1).known()); + ASSERT_FALSE(shape.dim(2).known()); + ASSERT_TRUE(shape.dim(3).known()); + ASSERT_EQ(1, shape.dim(0).value()); + ASSERT_EQ(2, shape.dim(1).value()); + ASSERT_EQ(0, shape.dim(2).value()); + ASSERT_EQ(4, shape.dim(3).value()); + + quantize.drop(); +} + +TEST(ShapeRuleTest, quantize_dynamic_shape_NEG) +{ + luci::CircleQuantize quantize; + luci::CircleInput input; + + input.shape_status(luci::ShapeStatus::UNDEFINED); + quantize.input(&input); + + loco::TensorShape shape; + luci::sinf::Rule shape_inf_rule; + + ASSERT_FALSE(shape_inf_rule.infer(&quantize, shape)); + + quantize.drop(); +} From 303c7eee56ec640e1f5011b4d2c57d1ed0126c79 Mon Sep 17 00:00:00 2001 From: bokyeong lee Date: Thu, 29 Aug 2024 09:10:40 +0900 Subject: [PATCH 2/3] [luci/quantize] modify tests without drop This commit modify tests without drop. ONE-DCO-1.0-Signed-off-by: kyeong8139 --- compiler/luci/service/src/Nodes/CircleQuantize.cpp | 3 ++- .../luci/service/src/Nodes/CircleQuantize.test.cpp | 10 +++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/compiler/luci/service/src/Nodes/CircleQuantize.cpp b/compiler/luci/service/src/Nodes/CircleQuantize.cpp index 85070f11bd8..95e165c2dde 100644 --- a/compiler/luci/service/src/Nodes/CircleQuantize.cpp +++ b/compiler/luci/service/src/Nodes/CircleQuantize.cpp @@ -29,7 +29,8 @@ luci::CircleNode *CloneNodeLet::visit(const luci::CircleQuantize *) loco::TensorShape sinf::Algorithm::visit(const luci::CircleQuantize *node) { - const auto input_shape = sinf::circle_shape(loco::must_cast(node->input())); + const auto input = loco::must_cast(node->input()); + const auto input_shape = sinf::circle_shape(input); return input_shape; } diff --git a/compiler/luci/service/src/Nodes/CircleQuantize.test.cpp b/compiler/luci/service/src/Nodes/CircleQuantize.test.cpp index 9cfa9ed8dbf..4e4363fcf0c 100644 --- a/compiler/luci/service/src/Nodes/CircleQuantize.test.cpp +++ b/compiler/luci/service/src/Nodes/CircleQuantize.test.cpp @@ -35,8 +35,8 @@ TEST(CloneNodeTest, clone_Quantize) TEST(ShapeRuleTest, quantize_dynamic_shape) { - luci::CircleQuantize quantize; luci::CircleInput input; + luci::CircleQuantize quantize; input.shape({1, 2, 3, 4}); input.shape_status(luci::ShapeStatus::VALID); @@ -58,14 +58,12 @@ TEST(ShapeRuleTest, quantize_dynamic_shape) ASSERT_EQ(2, shape.dim(1).value()); ASSERT_EQ(0, shape.dim(2).value()); ASSERT_EQ(4, shape.dim(3).value()); - - quantize.drop(); } -TEST(ShapeRuleTest, quantize_dynamic_shape_NEG) +TEST(ShapeRuleTest, quantize_shape_not_ready_NEG) { - luci::CircleQuantize quantize; luci::CircleInput input; + luci::CircleQuantize quantize; input.shape_status(luci::ShapeStatus::UNDEFINED); quantize.input(&input); @@ -74,6 +72,4 @@ TEST(ShapeRuleTest, quantize_dynamic_shape_NEG) luci::sinf::Rule shape_inf_rule; ASSERT_FALSE(shape_inf_rule.infer(&quantize, shape)); - - quantize.drop(); } From 51bdff705e53d382168c87412f9bc92d4695a067 Mon Sep 17 00:00:00 2001 From: bokyeong lee Date: Thu, 29 Aug 2024 09:46:44 +0900 Subject: [PATCH 3/3] [luci/service] use namespace This commit use namespace. ONE-DCO-1.0-Signed-off-by: kyeong8139 --- compiler/luci/service/src/Nodes/CircleQuantize.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/luci/service/src/Nodes/CircleQuantize.cpp b/compiler/luci/service/src/Nodes/CircleQuantize.cpp index 95e165c2dde..69c24dcbfe4 100644 --- a/compiler/luci/service/src/Nodes/CircleQuantize.cpp +++ b/compiler/luci/service/src/Nodes/CircleQuantize.cpp @@ -27,11 +27,16 @@ luci::CircleNode *CloneNodeLet::visit(const luci::CircleQuantize *) return _graph->nodes()->create(); } -loco::TensorShape sinf::Algorithm::visit(const luci::CircleQuantize *node) +namespace sinf +{ + +loco::TensorShape Algorithm::visit(const luci::CircleQuantize *node) { const auto input = loco::must_cast(node->input()); - const auto input_shape = sinf::circle_shape(input); + const auto input_shape = circle_shape(input); return input_shape; } +} // namespace sinf + } // namespace luci