From bb87417aff6568ccf874682fbaa3316260dbdde7 Mon Sep 17 00:00:00 2001 From: lichun Date: Thu, 18 Mar 2021 10:09:32 +0800 Subject: [PATCH 1/6] remove EXPERIMENTAL_DYNAMIC_PARTITION --- ge/graph/partition/dynamic_shape_partition.cc | 37 +++---------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/ge/graph/partition/dynamic_shape_partition.cc b/ge/graph/partition/dynamic_shape_partition.cc index 5736e39a..bd95d0c5 100755 --- a/ge/graph/partition/dynamic_shape_partition.cc +++ b/ge/graph/partition/dynamic_shape_partition.cc @@ -48,50 +48,23 @@ namespace ge { using Cluster = DynamicShapePartitioner::Cluster; using ClusterPtr = std::shared_ptr; -static bool IsInExperimentalMode(const ComputeGraphPtr &root_graph) { +static bool IsSingleOpScene(const ComputeGraphPtr &root_graph) { for (const auto &node : root_graph->GetAllNodes()) { GE_CHECK_NOTNULL(node->GetOpDesc()); // not do partition in single op scene. bool is_singleop = false; (void)AttrUtils::GetBool(node->GetOpDesc(), ATTR_SINGLE_OP_SCENE, is_singleop); if (is_singleop) { - return false; - } - - for (const auto &input_desc : node->GetOpDesc()->GetAllInputsDesc()) { - auto type = input_desc.GetDataType(); - if (type == DT_STRING || type == DT_RESOURCE || type == DT_STRING_REF) { - if (std::getenv("EXPERIMENTAL_DYNAMIC_PARTITION") == nullptr) { - return false; - } else { - GEEVENT("In dynamic shape scene, model contains data type:" - "DT_STRING/DT_RESOURCE/DT_STRING_REF may not be supported well " - "temporarily, please retry with \"unset EXPERIMENTAL_DYNAMIC_PARTITION\"."); - break; - } - } - } - for (const auto &output_desc : node->GetOpDesc()->GetAllOutputsDesc()) { - auto type = output_desc.GetDataType(); - if (type == DT_STRING || type == DT_RESOURCE || type == DT_STRING_REF) { - if (std::getenv("EXPERIMENTAL_DYNAMIC_PARTITION") == nullptr) { - return false; - } else { - GEEVENT("In dynamic shape scene, model contains data type:" - "DT_STRING/DT_RESOURCE/DT_STRING_REF may not be supported well " - "temporarily, please retry with \"unset EXPERIMENTAL_DYNAMIC_PARTITION\"."); - break; - } - } + return true; } } - return true; + return false; } Status DynamicShapePartitioner::Partition() { REQUIRE_NOT_NULL(root_graph_, "Graph is nullptr."); - if (!IsInExperimentalMode(root_graph_)) { - GELOGD("Skip dynamic shape partition as not in experimental mode."); + if (IsSingleOpScene(root_graph_)) { + GELOGD("Skip dynamic shape partition as in single op scene."); REQUIRE(AttrUtils::SetBool(*root_graph_, ATTR_NAME_DYNAMIC_SHAPE_PARTITIONED, false), "Failed set dynamic shape partitioned flag on root graph."); return SUCCESS; From 5337cefcd42e05006172d1b436bfdf4db8d7534c Mon Sep 17 00:00:00 2001 From: lichun Date: Thu, 18 Mar 2021 12:58:52 +0800 Subject: [PATCH 2/6] remove EXPERIMENTAL_DYNAMIC_PARTITION --- tests/ut/ge/CMakeLists.txt | 1 + .../dynamic_shape_partition_unittest.cc | 95 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 80636a20..f6a5d681 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -763,6 +763,7 @@ set(MULTI_PARTS_TEST_FILES "graph/preprocess/graph_preprocess_unittest.cc" "graph/manager/hcom_util_unittest.cc" "graph/manager/graph_caching_allocator_unittest.cc" + "graph/partition/dynamic_shape_partition_unittest.cc" "session/omg_omg_unittest.cc" ) diff --git a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc new file mode 100644 index 00000000..6a44f5ab --- /dev/null +++ b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc @@ -0,0 +1,95 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "graph/partition/dynamic_shape_partition.h" +#include "compute_graph.h" + +#define private public +#define protected public + +namespace ge { + +namespace { + +GeTensorDescPtr CreateTensorDesc(std::initializer_list shape, Format format = FORMAT_NCHW, + DataType data_type = DT_FLOAT) { + GeShape ge_shape{vector(shape)}; + GeTensorDescPtr tensor_desc = std::make_shared(); + tensor_desc->SetShape(ge_shape); + tensor_desc->SetFormat(format); + tensor_desc->SetDataType(data_type); + return tensor_desc; +} + +class NodeBuilder { + public: + NodeBuilder(const std::string &name, const std::string &type) { op_desc_ = std::make_shared(name, type); } + + NodeBuilder &AddInputDesc(std::initializer_list shape = {1, 1, 224, 224}, Format format = FORMAT_NCHW, + DataType data_type = DT_FLOAT) { + op_desc_->AddInputDesc(CreateTensorDesc(shape, format, data_type)->Clone()); + return *this; + } + + NodeBuilder &AddOutputDesc(std::initializer_list shape = {1, 1, 224, 224}, Format format = FORMAT_NCHW, + DataType data_type = DT_FLOAT) { + op_desc_->AddOutputDesc(CreateTensorDesc(shape, format, data_type)->Clone()); + return *this; + } + + NodeBuilder &AddOutputDesc(GeTensorDescPtr tensor_desc) { + op_desc_->AddOutputDesc(tensor_desc->Clone()); + return *this; + } + + NodePtr Build(const ComputeGraphPtr &graph) { + NodePtr node = graph->AddNode(op_desc_); + return node; + } + + private: + OpDescPtr op_desc_; +}; +} // namespace + +class UtestDynamicShapePartition : public testing::Test { + protected: + void SetUp() {} + + void TearDown() {} +}; + +// test Init_EndGraphTaskInfo_failed +TEST_F(UtestDynamicShapePartition, single_op_scene_success) { + ComputeGraphPtr computeGraph("default"); + + NodePtr node1 = + NodeBuilder("node1", CONSTANTOP).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph); + NodePtr add_n_node = + NodeBuilder("add_n_node", ADDN).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph); + NodePtr node2 = + NodeBuilder("node2", RELU).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph); + GraphUtils::AddEdge(node1->GetOutDataAnchor(0), add_n_node->GetInDataAnchor(0)); + GraphUtils::AddEdge(add_n_node->GetOutDataAnchor(0), node2->GetInDataAnchor(0)); + + (void)AttrUtils::SetBool(add_n_node->GetOpDesc(), ATTR_SINGLE_OP_SCENE, true); + + DynamicShapePartitioner partitioner(computeGraph); + EXPECT_EQ(partitioner.Partition(), SUCCESS); +} + +} // namespace ge \ No newline at end of file From 032a6974d0c1fcf3c052aaae1980235731d9b4f1 Mon Sep 17 00:00:00 2001 From: lichun Date: Thu, 18 Mar 2021 13:46:18 +0800 Subject: [PATCH 3/6] remove EXPERIMENTAL_DYNAMIC_PARTITION --- .../ge/graph/partition/dynamic_shape_partition_unittest.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc index 6a44f5ab..433f098a 100644 --- a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc +++ b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc @@ -17,6 +17,10 @@ #include #include "graph/partition/dynamic_shape_partition.h" #include "compute_graph.h" +#include "inc/framework/common/types.h" +#include "utils/graph_utils.h" +#include "graph/debug/ge_attr_define.h" + #define private public #define protected public @@ -75,7 +79,7 @@ class UtestDynamicShapePartition : public testing::Test { // test Init_EndGraphTaskInfo_failed TEST_F(UtestDynamicShapePartition, single_op_scene_success) { - ComputeGraphPtr computeGraph("default"); + ComputeGraphPtr graph = shared_ptr("default"); NodePtr node1 = NodeBuilder("node1", CONSTANTOP).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph); From 54087481bf4d4ab8b0b259d62ac238a5e2ac4ecb Mon Sep 17 00:00:00 2001 From: lichun Date: Thu, 18 Mar 2021 13:47:11 +0800 Subject: [PATCH 4/6] remove EXPERIMENTAL_DYNAMIC_PARTITION --- tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc index 433f098a..bc4bb102 100644 --- a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc +++ b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc @@ -92,7 +92,7 @@ TEST_F(UtestDynamicShapePartition, single_op_scene_success) { (void)AttrUtils::SetBool(add_n_node->GetOpDesc(), ATTR_SINGLE_OP_SCENE, true); - DynamicShapePartitioner partitioner(computeGraph); + DynamicShapePartitioner partitioner(graph); EXPECT_EQ(partitioner.Partition(), SUCCESS); } From 2e431b33be4bd9cd233310c6bd2e7942795627b8 Mon Sep 17 00:00:00 2001 From: lichun Date: Thu, 18 Mar 2021 13:48:56 +0800 Subject: [PATCH 5/6] remove EXPERIMENTAL_DYNAMIC_PARTITION --- .../ut/ge/graph/partition/dynamic_shape_partition_unittest.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc index bc4bb102..c7c983b5 100644 --- a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc +++ b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc @@ -77,9 +77,8 @@ class UtestDynamicShapePartition : public testing::Test { void TearDown() {} }; -// test Init_EndGraphTaskInfo_failed TEST_F(UtestDynamicShapePartition, single_op_scene_success) { - ComputeGraphPtr graph = shared_ptr("default"); + ComputeGraphPtr graph = std::make_shared("default"); NodePtr node1 = NodeBuilder("node1", CONSTANTOP).AddInputDesc({1, 1, 224, 224}).AddOutputDesc({1, 1, 224, 224}).Build(graph); From e2b62773293dddeb1a8cd4feff19638fc93e84c8 Mon Sep 17 00:00:00 2001 From: lichun Date: Thu, 18 Mar 2021 14:04:12 +0800 Subject: [PATCH 6/6] remove EXPERIMENTAL_DYNAMIC_PARTITION --- tests/ut/ge/CMakeLists.txt | 2 +- tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index f6a5d681..09c59081 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -763,7 +763,7 @@ set(MULTI_PARTS_TEST_FILES "graph/preprocess/graph_preprocess_unittest.cc" "graph/manager/hcom_util_unittest.cc" "graph/manager/graph_caching_allocator_unittest.cc" - "graph/partition/dynamic_shape_partition_unittest.cc" + "graph/partition/dynamic_shape_partition_unittest.cc" "session/omg_omg_unittest.cc" ) diff --git a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc index c7c983b5..b60e0ddd 100644 --- a/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc +++ b/tests/ut/ge/graph/partition/dynamic_shape_partition_unittest.cc @@ -94,5 +94,4 @@ TEST_F(UtestDynamicShapePartition, single_op_scene_success) { DynamicShapePartitioner partitioner(graph); EXPECT_EQ(partitioner.Partition(), SUCCESS); } - } // namespace ge \ No newline at end of file