diff --git a/ge/graph/passes/reshape_recovery_pass.cc b/ge/graph/passes/reshape_recovery_pass.cc index f0987ff5..3419fdb9 100644 --- a/ge/graph/passes/reshape_recovery_pass.cc +++ b/ge/graph/passes/reshape_recovery_pass.cc @@ -55,8 +55,9 @@ Status InsertReshapeIfNeed(const NodePtr &node) { GE_CHECK_NOTNULL(dst_node->GetOpDesc()); auto dst_tensor = dst_node->GetOpDesc()->GetInputDescPtr(dst_anchor->GetIdx()); GE_CHECK_NOTNULL(dst_tensor); - bool is_need_insert_reshape = src_tensor->GetShape().GetDims() != UNKNOWN_RANK && - dst_tensor->GetShape().GetDims() != UNKNOWN_RANK && + // Do not insert reshape node in dynamic shape. + bool is_need_insert_reshape = !src_tensor->GetShape().IsUnknownShape() && + !dst_tensor->GetShape().IsUnknownShape() && src_tensor->GetShape().GetDims() != dst_tensor->GetShape().GetDims(); if (is_need_insert_reshape) { auto reshape = CreateReshape(src_tensor, dst_tensor, node->GetOwnerComputeGraph()); diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index fcb1e6aa..97e071b6 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -703,6 +703,7 @@ set(PASS_TEST_FILES "graph/passes/link_gen_mask_nodes_pass_unittest.cc" "graph/passes/transpose_transdata_pass_unittest.cc" "graph/passes/parallel_group_pass_unittest.cc" + "graph/passes/reshape_recovery_pass_unittest.cc" ) set(KERNEL_TEST_FILES diff --git a/tests/ut/ge/graph/passes/reshape_recovery_pass_unittest.cc b/tests/ut/ge/graph/passes/reshape_recovery_pass_unittest.cc new file mode 100644 index 00000000..08f580e1 --- /dev/null +++ b/tests/ut/ge/graph/passes/reshape_recovery_pass_unittest.cc @@ -0,0 +1,55 @@ +/** + * 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 "graph/passes/reshape_recovery_pass.h" + +#include +#include +#include + +#include "graph_builder_utils.h" + +namespace ge { +class UtestReshapeRecoveryPass : public testing::Test { + protected: + void SetUp() {} + void TearDown() {} +}; + +namespace { +/// data +/// | +/// transdata +/// | +/// netoutput +ComputeGraphPtr BuilderGraph1() { + ut::GraphBuilder builder = ut::GraphBuilder("g1"); + auto data = builder.AddNode("data", "Data", 0, 1, FORMAT_ND, DT_FLOAT, {1, 3, 16, 16}); + auto transdata = builder.AddNode("transdata", "Transdata", 1, 1, FORMAT_ND, DT_FLOAT, {1, 3, 16, 16}); + auto netoutput = builder.AddNode("netoutput", "Netoutput", 1, 0, FORMAT_ND, DT_FLOAT, {1, 3, 16, 16}); + + builder.AddDataEdge(data, 0, transdata, 0); + builder.AddDataEdge(transdata, 0, netoutput, 0); + return builder.GetGraph(); +} +} + +TEST_F(UtestReshapeRecoveryPass, test_reshape_recovery) { + auto graph = BuilderGraph1(); + ReshapeRecoveryPass pass; + EXPECT_EQ(pass.Run(graph), SUCCESS); +} +} \ No newline at end of file