From 91c486f3d0fc9cb2e86390882ee44dad64099ab3 Mon Sep 17 00:00:00 2001 From: icodo98 Date: Wed, 21 Aug 2024 17:32:18 +0900 Subject: [PATCH 01/12] [luci] infer dynamic shape for pad This infers dynmic shape for pad. If input shape is unknown, output shape is also unknown. ONE-DCO-1.0-Signed-off-by: JuYoung Lee --- .../service/src/CircleShapeInferenceRule.cpp | 36 +++++++++------- .../luci/service/src/Nodes/CirclePad.test.cpp | 41 +++++++++++++++++++ 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/compiler/luci/service/src/CircleShapeInferenceRule.cpp b/compiler/luci/service/src/CircleShapeInferenceRule.cpp index 0d698e0130b..df64fff835f 100644 --- a/compiler/luci/service/src/CircleShapeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleShapeInferenceRule.cpp @@ -237,25 +237,33 @@ loco::NodeShape use_paddings(const CIRCLENODE *node, const luci::CircleConst *pa { int32_t idx = ni * 2; int value = input_shape.dim(ni).value(); - if (paddings->dtype() == S32) + if (!input_shape.dim(ni).known()) { - value += paddings->at(idx + 0); // left - value += paddings->at(idx + 1); // right + output_shape.dim(ni).unset(); } else { - auto pl = paddings->at(idx + 0); - auto pr = paddings->at(idx + 1); - auto max = static_cast(std::numeric_limits::max()); - auto low = static_cast(std::numeric_limits::lowest()); - LUCI_ASSERT(pl <= max, "paddings is over 32 bit limit"); - LUCI_ASSERT(pl >= low, "paddings is over 32 bit limit"); - LUCI_ASSERT(pr <= max, "paddings is over 32 bit limit"); - LUCI_ASSERT(pr >= low, "paddings is over 32 bit limit"); - value += static_cast(pl); // left - value += static_cast(pr); // right + + if (paddings->dtype() == S32) + { + value += paddings->at(idx + 0); // left + value += paddings->at(idx + 1); // right + } + else + { + auto pl = paddings->at(idx + 0); + auto pr = paddings->at(idx + 1); + auto max = static_cast(std::numeric_limits::max()); + auto low = static_cast(std::numeric_limits::lowest()); + LUCI_ASSERT(pl <= max, "paddings is over 32 bit limit"); + LUCI_ASSERT(pl >= low, "paddings is over 32 bit limit"); + LUCI_ASSERT(pr <= max, "paddings is over 32 bit limit"); + LUCI_ASSERT(pr >= low, "paddings is over 32 bit limit"); + value += static_cast(pl); // left + value += static_cast(pr); // right + } + output_shape.dim(ni) = value; } - output_shape.dim(ni) = value; } return loco::NodeShape{output_shape}; diff --git a/compiler/luci/service/src/Nodes/CirclePad.test.cpp b/compiler/luci/service/src/Nodes/CirclePad.test.cpp index 1d5f8375e1f..8e18d2b20ee 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.test.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.test.cpp @@ -16,6 +16,8 @@ #include "luci/Service/CircleNodeClone.h" +#include + #include TEST(CloneNodeTest, clone_Pad) @@ -31,3 +33,42 @@ TEST(CloneNodeTest, clone_Pad) auto cloned_pad = dynamic_cast(cloned); ASSERT_NE(nullptr, cloned_pad); } + +TEST(ShapeRuleTest, pad_dynamic_shape) +{ + luci::CirclePad pad; + luci::CircleInput input; + // Use circle input as paddings + luci::CircleConst padddings; + + loco::TensorShape shape; + luci::sinf::Rule shape_inf_rule; + + input.shape({1, 2, 3, 4}); + input.shape_status(luci::ShapeStatus::VALID); + input.dim(2).unset(); + + padddings.dtype(loco::DataType::S64); + padddings.shape({4, 2}); + padddings.shape_status(luci::ShapeStatus::VALID); + + const loco::DataType S64 = loco::DataType::S64; + uint32_t t = 64 * 8; + padddings.size(t); + + pad.input(&input); + pad.paddings(&padddings); + + ASSERT_TRUE(shape_inf_rule.infer(&pad, shape)); + ASSERT_EQ(shape.rank(), 4); + 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()); + pad.drop(); +} From cb7ccf7e4f02ff1e772bfcabd0a7b9bd34173d06 Mon Sep 17 00:00:00 2001 From: icodo98 Date: Thu, 22 Aug 2024 13:25:25 +0900 Subject: [PATCH 02/12] [luci] refactored infer dynamic pad input ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com --- .../service/src/CircleShapeInferenceRule.cpp | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/compiler/luci/service/src/CircleShapeInferenceRule.cpp b/compiler/luci/service/src/CircleShapeInferenceRule.cpp index df64fff835f..400dcd61111 100644 --- a/compiler/luci/service/src/CircleShapeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleShapeInferenceRule.cpp @@ -235,35 +235,32 @@ loco::NodeShape use_paddings(const CIRCLENODE *node, const luci::CircleConst *pa output_shape.rank(input_shape.rank()); for (int32_t ni = 0; ni < n; ++ni) { + if (not input_shape.dim(ni).known()) + { + output_shape.dim(ni).unset(); + continue; + } int32_t idx = ni * 2; int value = input_shape.dim(ni).value(); - if (!input_shape.dim(ni).known()) + if (paddings->dtype() == S32) { - output_shape.dim(ni).unset(); + value += paddings->at(idx + 0); // left + value += paddings->at(idx + 1); // right } else { - - if (paddings->dtype() == S32) - { - value += paddings->at(idx + 0); // left - value += paddings->at(idx + 1); // right - } - else - { - auto pl = paddings->at(idx + 0); - auto pr = paddings->at(idx + 1); - auto max = static_cast(std::numeric_limits::max()); - auto low = static_cast(std::numeric_limits::lowest()); - LUCI_ASSERT(pl <= max, "paddings is over 32 bit limit"); - LUCI_ASSERT(pl >= low, "paddings is over 32 bit limit"); - LUCI_ASSERT(pr <= max, "paddings is over 32 bit limit"); - LUCI_ASSERT(pr >= low, "paddings is over 32 bit limit"); - value += static_cast(pl); // left - value += static_cast(pr); // right - } - output_shape.dim(ni) = value; + auto pl = paddings->at(idx + 0); + auto pr = paddings->at(idx + 1); + auto max = static_cast(std::numeric_limits::max()); + auto low = static_cast(std::numeric_limits::lowest()); + LUCI_ASSERT(pl <= max, "paddings is over 32 bit limit"); + LUCI_ASSERT(pl >= low, "paddings is over 32 bit limit"); + LUCI_ASSERT(pr <= max, "paddings is over 32 bit limit"); + LUCI_ASSERT(pr >= low, "paddings is over 32 bit limit"); + value += static_cast(pl); // left + value += static_cast(pr); // right } + output_shape.dim(ni) = value; } return loco::NodeShape{output_shape}; From abcfd5c70cb508170dfe1f98df221c9d86deeebd Mon Sep 17 00:00:00 2001 From: icodo98 Date: Mon, 26 Aug 2024 15:49:17 +0900 Subject: [PATCH 03/12] [luci] add _NEG test case added _NEG test case for Pad ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com --- .../luci/service/src/Nodes/CirclePad.test.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/luci/service/src/Nodes/CirclePad.test.cpp b/compiler/luci/service/src/Nodes/CirclePad.test.cpp index 8e18d2b20ee..6250db7d753 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.test.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.test.cpp @@ -38,7 +38,6 @@ TEST(ShapeRuleTest, pad_dynamic_shape) { luci::CirclePad pad; luci::CircleInput input; - // Use circle input as paddings luci::CircleConst padddings; loco::TensorShape shape; @@ -72,3 +71,21 @@ TEST(ShapeRuleTest, pad_dynamic_shape) ASSERT_EQ(4, shape.dim(3).value()); pad.drop(); } + +TEST(ShapeRuleTest, pad_without_padding_NEG) +{ + luci::CirclePad pad; + luci::CircleInput input; + + loco::TensorShape shape; + luci::sinf::Rule shape_inf_rule; + + input.shape({1, 2, 3, 4}); + input.shape_status(luci::ShapeStatus::VALID); + input.dim(2).unset(); + + pad.input(&input); + ASSERT_ANY_THROW(shape_inf_rule.infer(&pad, shape)); + + pad.drop(); +} \ No newline at end of file From 8ff201bb80e51e55e79e146f3b2fe8629562e052 Mon Sep 17 00:00:00 2001 From: icodo98 Date: Mon, 26 Aug 2024 15:51:43 +0900 Subject: [PATCH 04/12] [luci] Migrate pad shape inference rule This migrates pad Op's shape inference rule to sinf::Algorithm. ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com --- .../luci/Service/CircleShapeInference.h | 2 +- .../service/src/CircleShapeInferenceHelper.h | 57 ++++++++++++++++++- .../service/src/CircleShapeInferenceRule.cpp | 9 --- compiler/luci/service/src/Nodes/CirclePad.cpp | 9 +++ 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/compiler/luci/service/include/luci/Service/CircleShapeInference.h b/compiler/luci/service/include/luci/Service/CircleShapeInference.h index 1ef947a5111..3e8d80391cf 100644 --- a/compiler/luci/service/include/luci/Service/CircleShapeInference.h +++ b/compiler/luci/service/include/luci/Service/CircleShapeInference.h @@ -107,7 +107,7 @@ class Algorithm final : public luci::CircleNodeVisitor // loco::TensorShape visit(const luci::CircleNotEqual *node) final; // loco::TensorShape visit(const luci::CircleOneHot *node) final; // loco::TensorShape visit(const luci::CirclePack *node) final; - // loco::TensorShape visit(const luci::CirclePad *node) final; + loco::TensorShape visit(const luci::CirclePad *node) final; // loco::TensorShape visit(const luci::CirclePadV2 *node) final; // loco::TensorShape visit(const luci::CirclePow *node) final; // loco::TensorShape visit(const luci::CirclePRelu *node) final; diff --git a/compiler/luci/service/src/CircleShapeInferenceHelper.h b/compiler/luci/service/src/CircleShapeInferenceHelper.h index 0d071c0505e..5dd268025ea 100644 --- a/compiler/luci/service/src/CircleShapeInferenceHelper.h +++ b/compiler/luci/service/src/CircleShapeInferenceHelper.h @@ -19,7 +19,7 @@ #include #include - +#include "Check.h" #include namespace luci @@ -87,6 +87,61 @@ class TensorShapeExpander final const loco::TensorShape _shape; }; +template +loco::TensorShape use_paddings(const CIRCLENODE *node, const luci::CircleConst *paddings) +{ + const loco::DataType S32 = loco::DataType::S32; + const loco::DataType S64 = loco::DataType::S64; + + auto input_shape = luci::shape_get(node->input()).template as(); + + // TODO support other data type + LUCI_ASSERT(paddings->dtype() == S32 || paddings->dtype() == S64, "Support int 32/64 for now"); + LUCI_ASSERT(paddings->rank() == 2, "paddings should be rank 2"); + + int32_t n = paddings->dim(0).value(); + int32_t v = paddings->dim(1).value(); + + LUCI_ASSERT(v == 2, "paddings should be [n, 2]"); + LUCI_ASSERT(n == int32_t(input_shape.rank()), + "paddings [n, 2] should have same value of input rank"); + + loco::TensorShape output_shape; + + output_shape.rank(input_shape.rank()); + for (int32_t ni = 0; ni < n; ++ni) + { + if (not input_shape.dim(ni).known()) + { + output_shape.dim(ni).unset(); + continue; + } + int32_t idx = ni * 2; + int value = input_shape.dim(ni).value(); + if (paddings->dtype() == S32) + { + value += paddings->at(idx + 0); // left + value += paddings->at(idx + 1); // right + } + else + { + auto pl = paddings->at(idx + 0); + auto pr = paddings->at(idx + 1); + auto max = static_cast(std::numeric_limits::max()); + auto low = static_cast(std::numeric_limits::lowest()); + LUCI_ASSERT(pl <= max, "paddings is over 32 bit limit"); + LUCI_ASSERT(pl >= low, "paddings is over 32 bit limit"); + LUCI_ASSERT(pr <= max, "paddings is over 32 bit limit"); + LUCI_ASSERT(pr >= low, "paddings is over 32 bit limit"); + value += static_cast(pl); // left + value += static_cast(pr); // right + } + output_shape.dim(ni) = value; + } + + return output_shape; +} + } // namespace sinf } // namespace luci diff --git a/compiler/luci/service/src/CircleShapeInferenceRule.cpp b/compiler/luci/service/src/CircleShapeInferenceRule.cpp index 400dcd61111..96761859bb9 100644 --- a/compiler/luci/service/src/CircleShapeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleShapeInferenceRule.cpp @@ -982,13 +982,6 @@ loco::NodeShape infer_pack(const luci::CirclePack *node) return loco::NodeShape{output_shape}; } -loco::NodeShape infer_pad(const luci::CirclePad *node) -{ - // TODO support non-const case - auto paddings = loco::must_cast(node->paddings()); - return use_paddings(node, paddings); -} - loco::NodeShape infer_pad_v2(const luci::CirclePadV2 *node) { // TODO support non-const case @@ -2230,8 +2223,6 @@ class ShapeInferenceAlgorithm final : public luci::CircleNodeVisitor + #include "CircleCloneNode.h" +#include "CircleShapeInferenceHelper.h" + namespace luci { @@ -23,5 +27,10 @@ luci::CircleNode *CloneNodeLet::visit(const luci::CirclePad *) { return _graph->nodes()->create(); } +loco::TensorShape sinf::Algorithm::visit(const luci::CirclePad *node) +{ + auto paddings = loco::must_cast(node->paddings()); + return use_paddings(node, paddings); +} } // namespace luci From b4a37f28d2156d065a855dafb2673457d1522f2f Mon Sep 17 00:00:00 2001 From: JUYOUNG LEE <102905512+icodo98@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:46:15 +0900 Subject: [PATCH 05/12] [luci/service] formatting code with suggestions. fix code format with suggestions. ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com Co-authored-by: SaeHie Park --- compiler/luci/service/src/Nodes/CirclePad.cpp | 6 +++--- compiler/luci/service/src/Nodes/CirclePad.test.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/luci/service/src/Nodes/CirclePad.cpp b/compiler/luci/service/src/Nodes/CirclePad.cpp index 95aa687d16b..0a955c1f4f5 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.cpp @@ -14,12 +14,11 @@ * limitations under the License. */ -#include - #include "CircleCloneNode.h" - #include "CircleShapeInferenceHelper.h" +#include "luci/Service/CircleShapeInference.h" + namespace luci { @@ -27,6 +26,7 @@ luci::CircleNode *CloneNodeLet::visit(const luci::CirclePad *) { return _graph->nodes()->create(); } + loco::TensorShape sinf::Algorithm::visit(const luci::CirclePad *node) { auto paddings = loco::must_cast(node->paddings()); diff --git a/compiler/luci/service/src/Nodes/CirclePad.test.cpp b/compiler/luci/service/src/Nodes/CirclePad.test.cpp index 6250db7d753..da5ffb1a98b 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.test.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.test.cpp @@ -88,4 +88,4 @@ TEST(ShapeRuleTest, pad_without_padding_NEG) ASSERT_ANY_THROW(shape_inf_rule.infer(&pad, shape)); pad.drop(); -} \ No newline at end of file +} From 8aa61385979a375bb31f84e54d5a05dded247743 Mon Sep 17 00:00:00 2001 From: icodo98 Date: Wed, 28 Aug 2024 11:03:40 +0900 Subject: [PATCH 06/12] [luci] move template function to new head file move use_paddings funtion to new .h file ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com --- .../service/src/CircleShapeInferenceHelper.h | 57 +----------- .../src/CircleShapeInferenceHelperPads.h | 86 +++++++++++++++++++ compiler/luci/service/src/Nodes/CirclePad.cpp | 5 +- 3 files changed, 90 insertions(+), 58 deletions(-) create mode 100644 compiler/luci/service/src/CircleShapeInferenceHelperPads.h diff --git a/compiler/luci/service/src/CircleShapeInferenceHelper.h b/compiler/luci/service/src/CircleShapeInferenceHelper.h index 5dd268025ea..0d071c0505e 100644 --- a/compiler/luci/service/src/CircleShapeInferenceHelper.h +++ b/compiler/luci/service/src/CircleShapeInferenceHelper.h @@ -19,7 +19,7 @@ #include #include -#include "Check.h" + #include namespace luci @@ -87,61 +87,6 @@ class TensorShapeExpander final const loco::TensorShape _shape; }; -template -loco::TensorShape use_paddings(const CIRCLENODE *node, const luci::CircleConst *paddings) -{ - const loco::DataType S32 = loco::DataType::S32; - const loco::DataType S64 = loco::DataType::S64; - - auto input_shape = luci::shape_get(node->input()).template as(); - - // TODO support other data type - LUCI_ASSERT(paddings->dtype() == S32 || paddings->dtype() == S64, "Support int 32/64 for now"); - LUCI_ASSERT(paddings->rank() == 2, "paddings should be rank 2"); - - int32_t n = paddings->dim(0).value(); - int32_t v = paddings->dim(1).value(); - - LUCI_ASSERT(v == 2, "paddings should be [n, 2]"); - LUCI_ASSERT(n == int32_t(input_shape.rank()), - "paddings [n, 2] should have same value of input rank"); - - loco::TensorShape output_shape; - - output_shape.rank(input_shape.rank()); - for (int32_t ni = 0; ni < n; ++ni) - { - if (not input_shape.dim(ni).known()) - { - output_shape.dim(ni).unset(); - continue; - } - int32_t idx = ni * 2; - int value = input_shape.dim(ni).value(); - if (paddings->dtype() == S32) - { - value += paddings->at(idx + 0); // left - value += paddings->at(idx + 1); // right - } - else - { - auto pl = paddings->at(idx + 0); - auto pr = paddings->at(idx + 1); - auto max = static_cast(std::numeric_limits::max()); - auto low = static_cast(std::numeric_limits::lowest()); - LUCI_ASSERT(pl <= max, "paddings is over 32 bit limit"); - LUCI_ASSERT(pl >= low, "paddings is over 32 bit limit"); - LUCI_ASSERT(pr <= max, "paddings is over 32 bit limit"); - LUCI_ASSERT(pr >= low, "paddings is over 32 bit limit"); - value += static_cast(pl); // left - value += static_cast(pr); // right - } - output_shape.dim(ni) = value; - } - - return output_shape; -} - } // namespace sinf } // namespace luci diff --git a/compiler/luci/service/src/CircleShapeInferenceHelperPads.h b/compiler/luci/service/src/CircleShapeInferenceHelperPads.h new file mode 100644 index 00000000000..5ffa1e64820 --- /dev/null +++ b/compiler/luci/service/src/CircleShapeInferenceHelperPads.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __LUCI_CIRCLE_SHAPE_INFERENCE_HELPER_PADS_H__ +#define __LUCI_CIRCLE_SHAPE_INFERENCE_HELPER_PADS_H__ + +#include "Check.h" + +#include +#include +#include + +namespace luci +{ +namespace sinf +{ + +template +loco::TensorShape use_paddings(const CIRCLENODE *node, const luci::CircleConst *paddings) +{ + const loco::DataType S32 = loco::DataType::S32; + const loco::DataType S64 = loco::DataType::S64; + + auto input_shape = luci::shape_get(node->input()).template as(); + // TODO support other data type + LUCI_ASSERT(paddings->dtype() == S32 || paddings->dtype() == S64, "Support int 32/64 for now"); + LUCI_ASSERT(paddings->rank() == 2, "paddings should be rank 2"); + + int32_t n = paddings->dim(0).value(); + int32_t v = paddings->dim(1).value(); + + LUCI_ASSERT(v == 2, "paddings should be [n, 2]"); + LUCI_ASSERT(n == int32_t(input_shape.rank()), + "paddings [n, 2] should have same value of input rank"); + + loco::TensorShape output_shape; + + output_shape.rank(input_shape.rank()); + for (int32_t ni = 0; ni < n; ++ni) + { + if (not input_shape.dim(ni).known()) + { + output_shape.dim(ni).unset(); + continue; + } + int32_t idx = ni * 2; + int value = input_shape.dim(ni).value(); + if (paddings->dtype() == S32) + { + value += paddings->at(idx + 0); // left + value += paddings->at(idx + 1); // right + } + else + { + auto pl = paddings->at(idx + 0); + auto pr = paddings->at(idx + 1); + auto max = static_cast(std::numeric_limits::max()); + auto low = static_cast(std::numeric_limits::lowest()); + LUCI_ASSERT(pl <= max, "paddings is over 32 bit limit"); + LUCI_ASSERT(pl >= low, "paddings is over 32 bit limit"); + LUCI_ASSERT(pr <= max, "paddings is over 32 bit limit"); + LUCI_ASSERT(pr >= low, "paddings is over 32 bit limit"); + value += static_cast(pl); // left + value += static_cast(pr); // right + } + output_shape.dim(ni) = value; + } + + return output_shape; +} +} // namespace sinf +} // namespace luci + +#endif diff --git a/compiler/luci/service/src/Nodes/CirclePad.cpp b/compiler/luci/service/src/Nodes/CirclePad.cpp index 0a955c1f4f5..f005528c9ad 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.cpp @@ -14,10 +14,11 @@ * limitations under the License. */ +#include "luci/Service/CircleShapeInference.h" + #include "CircleCloneNode.h" #include "CircleShapeInferenceHelper.h" - -#include "luci/Service/CircleShapeInference.h" +#include "CircleShapeInferenceHelperPads.h" namespace luci { From 764be419b210d0dcc952340c0d0a1fec06fb7c23 Mon Sep 17 00:00:00 2001 From: icodo98 Date: Wed, 28 Aug 2024 12:03:17 +0900 Subject: [PATCH 07/12] [luci] rename file rename file to HelperPads.h ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com --- .../src/{CircleShapeInferenceHelperPads.h => HelperPads.h} | 0 compiler/luci/service/src/Nodes/CirclePad.cpp | 2 +- compiler/luci/service/src/Nodes/CirclePad.test.cpp | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename compiler/luci/service/src/{CircleShapeInferenceHelperPads.h => HelperPads.h} (100%) diff --git a/compiler/luci/service/src/CircleShapeInferenceHelperPads.h b/compiler/luci/service/src/HelperPads.h similarity index 100% rename from compiler/luci/service/src/CircleShapeInferenceHelperPads.h rename to compiler/luci/service/src/HelperPads.h diff --git a/compiler/luci/service/src/Nodes/CirclePad.cpp b/compiler/luci/service/src/Nodes/CirclePad.cpp index f005528c9ad..2e25eafc150 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.cpp @@ -18,7 +18,7 @@ #include "CircleCloneNode.h" #include "CircleShapeInferenceHelper.h" -#include "CircleShapeInferenceHelperPads.h" +#include "HelperPads.h" namespace luci { diff --git a/compiler/luci/service/src/Nodes/CirclePad.test.cpp b/compiler/luci/service/src/Nodes/CirclePad.test.cpp index da5ffb1a98b..134285dcf47 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.test.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.test.cpp @@ -16,7 +16,7 @@ #include "luci/Service/CircleNodeClone.h" -#include +#include "luci/Service/CircleShapeInference.h" #include From 94c49c295d3c5f2c6cb5dac98d601bd21172b643 Mon Sep 17 00:00:00 2001 From: JUYOUNG LEE <102905512+icodo98@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:19:17 +0900 Subject: [PATCH 08/12] Apply suggestions from code review adjust format Co-authored-by: SaeHie Park --- compiler/luci/service/src/HelperPads.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/luci/service/src/HelperPads.h b/compiler/luci/service/src/HelperPads.h index 5ffa1e64820..40b43ecfd7e 100644 --- a/compiler/luci/service/src/HelperPads.h +++ b/compiler/luci/service/src/HelperPads.h @@ -20,6 +20,7 @@ #include #include + #include namespace luci @@ -80,7 +81,8 @@ loco::TensorShape use_paddings(const CIRCLENODE *node, const luci::CircleConst * return output_shape; } + } // namespace sinf } // namespace luci -#endif +#endif // __LUCI_CIRCLE_SHAPE_INFERENCE_HELPER_PADS_H__ From 816f375a01caeb7b5294ec9a804e25602c7aaf60 Mon Sep 17 00:00:00 2001 From: icodo98 Date: Wed, 28 Aug 2024 14:45:44 +0900 Subject: [PATCH 09/12] [luci] changed guard name changed guard name for HelperPads.h ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com --- compiler/luci/service/src/HelperPads.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/luci/service/src/HelperPads.h b/compiler/luci/service/src/HelperPads.h index 40b43ecfd7e..b4c925b91be 100644 --- a/compiler/luci/service/src/HelperPads.h +++ b/compiler/luci/service/src/HelperPads.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef __LUCI_CIRCLE_SHAPE_INFERENCE_HELPER_PADS_H__ -#define __LUCI_CIRCLE_SHAPE_INFERENCE_HELPER_PADS_H__ +#ifndef __LUCI_SERVICE_HELPER_PADS_H__ +#define __LUCI_SERVICE_HELPER_PADS_H__ #include "Check.h" @@ -85,4 +85,4 @@ loco::TensorShape use_paddings(const CIRCLENODE *node, const luci::CircleConst * } // namespace sinf } // namespace luci -#endif // __LUCI_CIRCLE_SHAPE_INFERENCE_HELPER_PADS_H__ +#endif // __LUCI_SERVICE_HELPER_PADS_H__ From 8e9d0a3ba665a3fb1e7bd415c00f8b8aa8fc2f39 Mon Sep 17 00:00:00 2001 From: icodo98 Date: Wed, 28 Aug 2024 15:56:14 +0900 Subject: [PATCH 10/12] [luci] Refactored namespace Explicitly express namespace sinf int CiclePad.cpp. ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com --- compiler/luci/service/src/CircleShapeInferenceRule.cpp | 5 ----- compiler/luci/service/src/Nodes/CirclePad.cpp | 6 +++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/luci/service/src/CircleShapeInferenceRule.cpp b/compiler/luci/service/src/CircleShapeInferenceRule.cpp index 96761859bb9..864b013218d 100644 --- a/compiler/luci/service/src/CircleShapeInferenceRule.cpp +++ b/compiler/luci/service/src/CircleShapeInferenceRule.cpp @@ -235,11 +235,6 @@ loco::NodeShape use_paddings(const CIRCLENODE *node, const luci::CircleConst *pa output_shape.rank(input_shape.rank()); for (int32_t ni = 0; ni < n; ++ni) { - if (not input_shape.dim(ni).known()) - { - output_shape.dim(ni).unset(); - continue; - } int32_t idx = ni * 2; int value = input_shape.dim(ni).value(); if (paddings->dtype() == S32) diff --git a/compiler/luci/service/src/Nodes/CirclePad.cpp b/compiler/luci/service/src/Nodes/CirclePad.cpp index 2e25eafc150..81349065dda 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.cpp @@ -28,10 +28,14 @@ luci::CircleNode *CloneNodeLet::visit(const luci::CirclePad *) return _graph->nodes()->create(); } -loco::TensorShape sinf::Algorithm::visit(const luci::CirclePad *node) +namespace sinf +{ + +loco::TensorShape Algorithm::visit(const luci::CirclePad *node) { auto paddings = loco::must_cast(node->paddings()); return use_paddings(node, paddings); } +} // namespace sinf } // namespace luci From 55ae60365f371290189a1e48674aa0e3068fe8aa Mon Sep 17 00:00:00 2001 From: JUYOUNG LEE <102905512+icodo98@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:13:21 +0900 Subject: [PATCH 11/12] add to-do add to-do for non-const case Co-authored-by: SaeHie Park --- compiler/luci/service/src/Nodes/CirclePad.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/luci/service/src/Nodes/CirclePad.cpp b/compiler/luci/service/src/Nodes/CirclePad.cpp index 81349065dda..5212e59bdc6 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.cpp @@ -33,6 +33,7 @@ namespace sinf loco::TensorShape Algorithm::visit(const luci::CirclePad *node) { + // TODO support non-const case auto paddings = loco::must_cast(node->paddings()); return use_paddings(node, paddings); } From 39ae0f0297254e19662d5a01514a010e864ca04d Mon Sep 17 00:00:00 2001 From: icodo98 Date: Wed, 28 Aug 2024 17:58:59 +0900 Subject: [PATCH 12/12] [luci] use graph use graph() in test code. ONE-DCO-1.0-Signed-off-by: JuYoung Lee rsb98759@gmail.com --- .../luci/service/src/Nodes/CirclePad.test.cpp | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/compiler/luci/service/src/Nodes/CirclePad.test.cpp b/compiler/luci/service/src/Nodes/CirclePad.test.cpp index 134285dcf47..a3413642320 100644 --- a/compiler/luci/service/src/Nodes/CirclePad.test.cpp +++ b/compiler/luci/service/src/Nodes/CirclePad.test.cpp @@ -36,29 +36,31 @@ TEST(CloneNodeTest, clone_Pad) TEST(ShapeRuleTest, pad_dynamic_shape) { - luci::CirclePad pad; - luci::CircleInput input; - luci::CircleConst padddings; + auto g = loco::make_graph(); + auto node_pad = g->nodes()->create(); + + auto node_paddings = g->nodes()->create(); + auto node_input = g->nodes()->create(); loco::TensorShape shape; luci::sinf::Rule shape_inf_rule; - input.shape({1, 2, 3, 4}); - input.shape_status(luci::ShapeStatus::VALID); - input.dim(2).unset(); + node_input->shape({1, 2, 3, 4}); + node_input->shape_status(luci::ShapeStatus::VALID); + node_input->dim(2).unset(); - padddings.dtype(loco::DataType::S64); - padddings.shape({4, 2}); - padddings.shape_status(luci::ShapeStatus::VALID); + node_paddings->dtype(loco::DataType::S64); + node_paddings->shape({4, 2}); + node_paddings->shape_status(luci::ShapeStatus::VALID); const loco::DataType S64 = loco::DataType::S64; uint32_t t = 64 * 8; - padddings.size(t); + node_paddings->size(t); - pad.input(&input); - pad.paddings(&padddings); + node_pad->input(node_input); + node_pad->paddings(node_paddings); - ASSERT_TRUE(shape_inf_rule.infer(&pad, shape)); + ASSERT_TRUE(shape_inf_rule.infer(node_pad, shape)); ASSERT_EQ(shape.rank(), 4); ASSERT_TRUE(shape.dim(0).known()); ASSERT_TRUE(shape.dim(1).known()); @@ -69,23 +71,22 @@ TEST(ShapeRuleTest, pad_dynamic_shape) ASSERT_EQ(2, shape.dim(1).value()); ASSERT_EQ(0, shape.dim(2).value()); ASSERT_EQ(4, shape.dim(3).value()); - pad.drop(); } TEST(ShapeRuleTest, pad_without_padding_NEG) { - luci::CirclePad pad; - luci::CircleInput input; + auto g = loco::make_graph(); + auto node_pad = g->nodes()->create(); + auto node_input = g->nodes()->create(); loco::TensorShape shape; luci::sinf::Rule shape_inf_rule; - input.shape({1, 2, 3, 4}); - input.shape_status(luci::ShapeStatus::VALID); - input.dim(2).unset(); + node_input->shape({1, 2, 3, 4}); + node_input->shape_status(luci::ShapeStatus::VALID); + node_input->dim(2).unset(); - pad.input(&input); - ASSERT_ANY_THROW(shape_inf_rule.infer(&pad, shape)); + node_pad->input(node_input); - pad.drop(); -} + ASSERT_ANY_THROW(shape_inf_rule.infer(node_pad, shape)); +} \ No newline at end of file