forked from mindspore-Ecosystem/mindspore
Ignore tranformation of parallel if for special case of return in while/for loop
This commit is contained in:
parent
606a988268
commit
06097cc7e6
|
@ -685,5 +685,8 @@ CNodePtr FunctionBlock::GetJumpNode(FunctionBlock *target_block) {
|
|||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void FunctionBlock::SetReturnStatementInside() { is_return_statement_inside_ = true; }
|
||||
void FunctionBlock::SetBreakContinueStatementInside() { is_break_continue_statement_inside_ = true; }
|
||||
} // namespace parse
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -90,6 +90,11 @@ class FunctionBlock : public std::enable_shared_from_this<FunctionBlock> {
|
|||
void SetAsDeadBlock();
|
||||
CNodePtr GetJumpNode(FunctionBlock *target_block);
|
||||
|
||||
bool is_return_statement_inside() const { return is_return_statement_inside_; }
|
||||
void SetReturnStatementInside();
|
||||
bool is_break_continue_statement_inside() const { return is_break_continue_statement_inside_; }
|
||||
void SetBreakContinueStatementInside();
|
||||
|
||||
const py::dict &global_py_params() const { return global_py_params_; }
|
||||
void set_global_py_params(const py::dict &symbols) { global_py_params_ = symbols; }
|
||||
void AddGlobalPyParam(const std::string &name, const py::object &obj) {
|
||||
|
@ -205,6 +210,13 @@ class FunctionBlock : public std::enable_shared_from_this<FunctionBlock> {
|
|||
|
||||
AnfNodePtr ReadLocalVariable(const std::string &var_name);
|
||||
std::pair<AnfNodePtr, bool> FindPredInterpretNode(const std::string &var_name);
|
||||
// Flags help for determine if parallel-if transformation can be performed or not.
|
||||
// If inside this block include all inner block there is a return statement.
|
||||
// This flag will propagate beyond outer if/else or while/for loop, but not if-by-if;
|
||||
bool is_return_statement_inside_{false};
|
||||
// If inside this block there is a break/continue statement.
|
||||
// This flag will propagate beyond outer if/else but not while/for loop, if-by-if;
|
||||
bool is_break_continue_statement_inside_{false};
|
||||
};
|
||||
} // namespace parse
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -683,14 +683,25 @@ FunctionBlockPtr Parser::ParseStatements(FunctionBlockPtr block, const py::objec
|
|||
auto node_list = py::cast<py::list>(nodes);
|
||||
size_t count = py::len(node_list);
|
||||
MS_LOG(DEBUG) << "The nodes count is " << count;
|
||||
auto sub_block = block;
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
MS_LOG(DEBUG) << "Start parse statement[" << i << "]: " << py::str(node_list[i]);
|
||||
MS_LOG(DEBUG) << "Start parse statement[" << i << "]: " << py::str(node_list[i])
|
||||
<< ", block: " << sub_block->ToString();
|
||||
auto node = node_list[i];
|
||||
block = ParseStatement(block, node);
|
||||
MS_EXCEPTION_IF_NULL(block);
|
||||
MS_EXCEPTION_IF_NULL(block->func_graph());
|
||||
// Flag of return statement is set on sub_block inside ParseStatement, so use next_block
|
||||
// to store the returned block temporarily.
|
||||
auto next_block = ParseStatement(sub_block, node);
|
||||
MS_EXCEPTION_IF_NULL(next_block);
|
||||
MS_EXCEPTION_IF_NULL(next_block->func_graph());
|
||||
// Propagate flag of return statement back;
|
||||
if (sub_block != block && sub_block->is_return_statement_inside()) {
|
||||
MS_LOG(DEBUG) << "Sub block: " << sub_block->ToString()
|
||||
<< " has return statement inside, propagate flag back to block: " << block->ToString();
|
||||
block->SetReturnStatementInside();
|
||||
}
|
||||
sub_block = next_block;
|
||||
// Insert appropriate depended items for the function block if it has a return node
|
||||
if (block->func_graph()->get_return() != nullptr || block->is_dead_block()) {
|
||||
if (sub_block->func_graph()->get_return() != nullptr || sub_block->is_dead_block()) {
|
||||
// If break is not the last expr.
|
||||
if (i != count - 1) {
|
||||
TraceGuard trace_guard(GetLocation(node_list[i + 1]));
|
||||
|
@ -700,7 +711,7 @@ FunctionBlockPtr Parser::ParseStatements(FunctionBlockPtr block, const py::objec
|
|||
break;
|
||||
}
|
||||
}
|
||||
return block;
|
||||
return sub_block;
|
||||
}
|
||||
|
||||
FunctionBlockPtr Parser::ParseStatement(const FunctionBlockPtr &block, const py::object &node) {
|
||||
|
@ -776,7 +787,7 @@ FunctionBlockPtr Parser::ParseExpr(const FunctionBlockPtr &block, const py::obje
|
|||
py::object value_object = expand_info[1];
|
||||
// Make a Expr CNode.
|
||||
AnfNodePtr call_node = ParseExprNode(block, value_object);
|
||||
if (py::len(expand_info) == 2) {
|
||||
if (py::len(expand_info) == expect_size) {
|
||||
// Expression that not assigned to any variable.
|
||||
// This is usually a call with side effects.
|
||||
// e.g.: print(x)
|
||||
|
@ -887,6 +898,8 @@ FunctionBlockPtr Parser::ParseReturn(const FunctionBlockPtr &block, const py::ob
|
|||
auto func_graph = block->func_graph();
|
||||
CNodePtr return_cnode = func_graph->NewCNodeInOrder({NewValueNode(prim::kPrimReturn), return_expr_node});
|
||||
func_graph->set_return(return_cnode);
|
||||
MS_LOG(DEBUG) << "Inside the block has return statement, block: " << block->ToString();
|
||||
block->SetReturnStatementInside();
|
||||
return block;
|
||||
}
|
||||
|
||||
|
@ -1756,6 +1769,35 @@ FunctionBlockPtr Parser::ParseGlobal(const FunctionBlockPtr &block, const py::ob
|
|||
return block;
|
||||
}
|
||||
|
||||
void Parser::CheckControlFlowAlterationInIf(std::pair<FunctionBlockPtr, FunctionBlockPtr> *branch_graphs_pair,
|
||||
const FunctionBlockPtr &branch_block, const FunctionBlockPtr &branch_end,
|
||||
const FunctionBlockPtr &after_block, const FunctionBlockPtr &block) {
|
||||
if (branch_block->is_return_statement_inside()) {
|
||||
MS_LOG(DEBUG)
|
||||
<< "Inside the branch block has return statement, ignore for transformation to parallel-if call, branch block:"
|
||||
<< branch_block->ToString() << ", block: " << block->ToString();
|
||||
block->SetReturnStatementInside();
|
||||
return;
|
||||
}
|
||||
if (branch_end->func_graph()->get_return() != nullptr) {
|
||||
MS_LOG(DEBUG) << "Ignore the block as branch_end will not call after_block, branch_block: "
|
||||
<< branch_block->ToString() << ", branch_end: " << branch_end->ToString()
|
||||
<< ", after_block: " << after_block->ToString();
|
||||
branch_block->SetBreakContinueStatementInside();
|
||||
}
|
||||
if (branch_block->is_break_continue_statement_inside()) {
|
||||
MS_LOG(DEBUG) << "Inside the branch block has break or continue statement, ignore for transformation to "
|
||||
"parallel-if call, branch block: "
|
||||
<< branch_block->ToString() << ", branch end: " << branch_end->ToString()
|
||||
<< ", block: " << block->ToString();
|
||||
MS_LOG(DEBUG) << "Propagate flag of break or continue statement from branch block to block, branch block:"
|
||||
<< branch_block->ToString() << ", block: " << block->ToString();
|
||||
block->SetBreakContinueStatementInside();
|
||||
} else {
|
||||
branch_graphs_pair->second = branch_end;
|
||||
}
|
||||
}
|
||||
|
||||
// Process a if statement
|
||||
FunctionBlockPtr Parser::ParseIf(const FunctionBlockPtr &block, const py::object &node) {
|
||||
MS_LOG(DEBUG) << "Process ast If";
|
||||
|
@ -1798,56 +1840,35 @@ FunctionBlockPtr Parser::ParseIf(const FunctionBlockPtr &block, const py::object
|
|||
py::object bodyNode = python_adapter::GetPyObjAttr(node, "body");
|
||||
FunctionBlockPtr true_end = ParseStatements(true_block, bodyNode);
|
||||
MS_EXCEPTION_IF_NULL(true_end->func_graph());
|
||||
bool return_of_true_end_is_set = true, return_of_false_end_is_set = true;
|
||||
CheckControlFlowAlterationInIf(&true_branch_graphs, true_block, true_end, after_block, block);
|
||||
// If the return_ is set, it has its own continuation block
|
||||
if (true_end->func_graph()->get_return() == nullptr) {
|
||||
return_of_true_end_is_set = false;
|
||||
true_end->Jump(after_block, {});
|
||||
MS_LOG(DEBUG) << "The true_end block jump to after, true_block: " << true_block->ToString()
|
||||
<< ", true_end: " << true_end->ToString() << ", after: " << after_block->ToString();
|
||||
if (ignored_if_latter_call_graphs_.find(true_end) == ignored_if_latter_call_graphs_.end()) {
|
||||
true_branch_graphs.second = true_end;
|
||||
} else {
|
||||
MS_LOG(DEBUG) << "Ignore the true_end block for transform to parallem call, true_block: "
|
||||
<< true_block->ToString() << ", true_end: " << true_end->ToString();
|
||||
(void)ignored_if_latter_call_graphs_.insert(after_block);
|
||||
}
|
||||
if (use_fallback) {
|
||||
after_block->UpdateGlobalPyParam(true_end->global_py_params());
|
||||
}
|
||||
}
|
||||
|
||||
// Process the orelse branch
|
||||
std::pair<FunctionBlockPtr, FunctionBlockPtr> false_branch_graphs;
|
||||
py::object orelseNode = python_adapter::GetPyObjAttr(node, "orelse");
|
||||
FunctionBlockPtr false_end = ParseStatements(false_block, orelseNode);
|
||||
MS_EXCEPTION_IF_NULL(false_end->func_graph());
|
||||
CheckControlFlowAlterationInIf(&false_branch_graphs, false_block, false_end, after_block, block);
|
||||
// If the return_ is set, it has its own continuation block
|
||||
if (false_end->func_graph()->get_return() == nullptr) {
|
||||
return_of_false_end_is_set = false;
|
||||
false_end->Jump(after_block, {});
|
||||
MS_LOG(DEBUG) << "The false_end block jump to after, false_block: " << false_block->ToString()
|
||||
<< ", false_end: " << false_end->ToString() << ", after: " << after_block->ToString();
|
||||
if (ignored_if_latter_call_graphs_.find(false_end) == ignored_if_latter_call_graphs_.end()) {
|
||||
false_branch_graphs.second = false_end;
|
||||
} else {
|
||||
MS_LOG(DEBUG) << "Ignore the false_end block for transform to parallem call, false_block: "
|
||||
<< false_block->ToString() << ", false_end: " << false_end->ToString();
|
||||
(void)ignored_if_latter_call_graphs_.insert(after_block);
|
||||
}
|
||||
if (use_fallback) {
|
||||
after_block->UpdateGlobalPyParam(false_end->global_py_params());
|
||||
}
|
||||
}
|
||||
|
||||
auto switch_app = block->ConditionalJump(bool_node, true_block, false_block);
|
||||
|
||||
// Record the former, middle, latter graphs info.
|
||||
if (return_of_true_end_is_set || return_of_false_end_is_set) {
|
||||
MS_LOG(DEBUG) << "True_end or false_end will not call after_block, true_block: " << true_block->ToString()
|
||||
<< ", true_end: " << true_end->ToString() << ", false_block: " << false_block->ToString()
|
||||
<< ", false_end: " << false_end->ToString() << ", after_block: " << after_block->ToString();
|
||||
(void)ignored_if_latter_call_graphs_.insert(after_block);
|
||||
}
|
||||
static const auto transform_tail_call_to_parallel_call = (common::GetEnv("MS_DEV_IF_PARALLEL_CALL") != "0");
|
||||
if (transform_tail_call_to_parallel_call && true_branch_graphs.second != nullptr &&
|
||||
false_branch_graphs.second != nullptr) {
|
||||
|
@ -1874,6 +1895,16 @@ FunctionBlockPtr Parser::ParseIf(const FunctionBlockPtr &block, const py::object
|
|||
return after_block;
|
||||
}
|
||||
|
||||
void Parser::CheckReturnInLoop(const FunctionBlockPtr &block, const FunctionBlockPtr &header_block,
|
||||
const FunctionBlockPtr &body_block, const FunctionBlockPtr &after_block) {
|
||||
// Propagate flag of return statement in body_block back.
|
||||
if (body_block->is_return_statement_inside()) {
|
||||
MS_LOG(DEBUG) << "Propagate flag of return statement in body_block back, body_block: " << body_block->ToString()
|
||||
<< ", block: " << block->ToString();
|
||||
block->SetReturnStatementInside();
|
||||
}
|
||||
}
|
||||
|
||||
FunctionBlockPtr Parser::ParseWhile(const FunctionBlockPtr &block, const py::object &node) {
|
||||
MS_LOG(DEBUG) << "Process ast While";
|
||||
MS_EXCEPTION_IF_NULL(block);
|
||||
|
@ -1936,9 +1967,11 @@ FunctionBlockPtr Parser::ParseWhile(const FunctionBlockPtr &block, const py::obj
|
|||
if (end_block) {
|
||||
after_block->Jump(end_block, {});
|
||||
end_block->Mature();
|
||||
CheckReturnInLoop(block, header_block, body_block, after_block);
|
||||
return end_block;
|
||||
}
|
||||
// No 'break', no end_block.
|
||||
CheckReturnInLoop(block, header_block, body_block, after_block);
|
||||
return after_block;
|
||||
}
|
||||
|
||||
|
@ -2083,9 +2116,11 @@ FunctionBlockPtr Parser::ParseForUnroll(const FunctionBlockPtr &block, const py:
|
|||
// end_block exists if we encounter 'break' in loop body.
|
||||
after_block->Jump(end_block, {});
|
||||
end_block->Mature();
|
||||
CheckReturnInLoop(block, header_block, body_block, after_block);
|
||||
return end_block;
|
||||
}
|
||||
// No 'break', no end_block.
|
||||
CheckReturnInLoop(block, header_block, body_block, after_block);
|
||||
return after_block;
|
||||
}
|
||||
|
||||
|
|
|
@ -333,6 +333,13 @@ class Parser {
|
|||
AnfNodePtr GenerateMakeTuple(const FunctionBlockPtr &block, const std::vector<AnfNodePtr> &element_nodes);
|
||||
// Check if the node is pop operation.
|
||||
bool IsPopOperation(const AnfNodePtr &node);
|
||||
// Check if branch block contains break/continue/return statement, and propagate that flag back to block.
|
||||
void CheckControlFlowAlterationInIf(std::pair<FunctionBlockPtr, FunctionBlockPtr> *branch_graphs_pair,
|
||||
const FunctionBlockPtr &branch_block, const FunctionBlockPtr &branch_end,
|
||||
const FunctionBlockPtr &after_block, const FunctionBlockPtr &block);
|
||||
// Check if body block contains return statement, and propagate that flag back to block.
|
||||
void CheckReturnInLoop(const FunctionBlockPtr &block, const FunctionBlockPtr &header_block,
|
||||
const FunctionBlockPtr &body_block, const FunctionBlockPtr &after_block);
|
||||
|
||||
// The shared_ptr will be hold by GraphManager, so just hold a weak ref here.
|
||||
static FuncGraphWeakPtr top_func_graph_;
|
||||
|
@ -364,8 +371,6 @@ class Parser {
|
|||
std::vector<std::tuple<CNodePtr, FunctionBlockPtr, FunctionBlockPtr>> if_branch_calls_;
|
||||
// The rolled_body callers info. for later lifting operation.
|
||||
std::vector<std::pair<CNodePtr, FunctionBlockPtr>> rolled_body_calls_;
|
||||
// Add exception for if parallel transform.
|
||||
std::set<FunctionBlockPtr> ignored_if_latter_call_graphs_;
|
||||
};
|
||||
|
||||
// AST node type define code to ast
|
||||
|
|
|
@ -0,0 +1,929 @@
|
|||
# Copyright 2022 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.
|
||||
# ============================================================================
|
||||
import mindspore.context as context
|
||||
from mindspore import Tensor, ms_function
|
||||
from mindspore.common import dtype as mstype
|
||||
|
||||
|
||||
def setup_module():
|
||||
context.set_context(mode=context.GRAPH_MODE)
|
||||
|
||||
|
||||
def test_while_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in while loop requires that the after-if func graph should not
|
||||
be called.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_in_while_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
if y > 0:
|
||||
return bias
|
||||
x = x - 1
|
||||
y = y + 1
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_else_break_in_while_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
if y > 0:
|
||||
return bias
|
||||
break
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_else_return_in_while_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
if y > 0:
|
||||
return bias
|
||||
return x
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_break_else_return_in_while_in_else_take_break():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part.
|
||||
Expectation: take the break branch, success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
if y > 0:
|
||||
break
|
||||
return x
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_break_else_return_in_while_in_else_take_return():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part.
|
||||
Expectation: take the return branch, success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
if y < 0:
|
||||
break
|
||||
return x
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([4], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_while_return_in_while_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through outer while to
|
||||
the else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
while x > 0:
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_in_while_in_while_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through outer while to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
while x > 0:
|
||||
if y > 0:
|
||||
return bias
|
||||
x = x - 1
|
||||
y = y + 1
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_else_return_in_while_in_while_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
while x > 0:
|
||||
if y > 0:
|
||||
return bias
|
||||
return x
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_while_return_after_if_else_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part. The inner if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
|
||||
while x > 0:
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_after_while_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part. The inner if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
return bias
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_after_if_else_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner second if requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through if to
|
||||
the outer else part. The inner first if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
|
||||
if x > 0:
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_after_if_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner second if requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through if to
|
||||
the outer else part. The inner second if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
if x > 0:
|
||||
return bias
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_while_return_in_else_after_if_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part. The first if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_after_by_while_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part. The second if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
while x > 0:
|
||||
return bias
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_in_else_after_if_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in else of the second if/else requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through if to
|
||||
the outer else part. The first if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
if x > 0:
|
||||
return bias
|
||||
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_after_by_if_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner second if requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through if to
|
||||
the outer else part. The second first if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
if x > 0:
|
||||
return bias
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_in_if_while_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner while loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through while to
|
||||
the outer else part. The inner if/else in the first if can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
else:
|
||||
while x > 0:
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_in_if_if_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in else of the first if/else requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through if to
|
||||
the outer else part. The if/else inside the first if can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
else:
|
||||
if x > 0:
|
||||
return bias
|
||||
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_for_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in for loop requires that the after-if func graph should not
|
||||
be called.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_in_for_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
if y > 0:
|
||||
return bias
|
||||
x = x - 1
|
||||
y = y + 1
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_else_break_in_for_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
if y > 0:
|
||||
return bias
|
||||
break
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_else_return_in_for_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
if y > 0:
|
||||
return bias
|
||||
return x
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_for_return_in_for_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through outer for to
|
||||
the else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
for _ in range(5):
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_in_for_in_for_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through outer for to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
for _ in range(5):
|
||||
if y > 0:
|
||||
return bias
|
||||
x = x - 1
|
||||
y = y + 1
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_return_else_return_in_for_in_for_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
for _ in range(5):
|
||||
if y > 0:
|
||||
return bias
|
||||
return x
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_for_return_after_if_else_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part. The inner if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
|
||||
for _ in range(5):
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_after_for_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part. The inner if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
return bias
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_for_return_in_else_after_if_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part. The first if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_after_by_for_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part. The second if/else can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
else:
|
||||
for _ in range(5):
|
||||
return bias
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
||||
|
||||
|
||||
def test_if_else_in_if_for_return_in_else():
|
||||
"""
|
||||
Feature: Parallel if transformation.
|
||||
Description: return in inner for loop requires that the after-if func graph should not
|
||||
be called, and this information should be propagated through for to
|
||||
the outer else part. The inner if/else in the first if can be transformed.
|
||||
Expectation: success
|
||||
"""
|
||||
|
||||
@ms_function
|
||||
def foo(x, y, bias):
|
||||
if bias > y:
|
||||
y = x + y
|
||||
if x > y:
|
||||
x = x + y
|
||||
else:
|
||||
x = x - y
|
||||
else:
|
||||
for _ in range(5):
|
||||
return bias
|
||||
return x + y
|
||||
|
||||
x = Tensor([4], mstype.int32)
|
||||
y = Tensor([1], mstype.int32)
|
||||
bias = Tensor([-5], mstype.int32)
|
||||
expect = Tensor([-5], mstype.int32)
|
||||
ret = foo(x, y, bias)
|
||||
assert ret == expect
|
|
@ -78,6 +78,44 @@ class TestParallelIf : public UT::Common {
|
|||
abstract::AnalysisResultCacheMgr::GetInstance().Clear();
|
||||
abstract::AnalysisContext::ClearContext();
|
||||
}
|
||||
|
||||
void CheckParallelIfTransformationCount(const std::string &test_case, int expected_count) {
|
||||
FuncGraphPtr func_graph = getPyFun.CallAndParseRet(test_case);
|
||||
ASSERT_TRUE(func_graph != nullptr);
|
||||
|
||||
int count = 0;
|
||||
|
||||
auto manager = mindspore::Manage(func_graph, true);
|
||||
|
||||
// Get user cnode of all switch cnode: switch(cond, branch1, branch2)();
|
||||
AnfNodePtrList switch_cnodes_user;
|
||||
const auto &node_users = manager->node_users();
|
||||
for (const auto &node : manager->all_nodes()) {
|
||||
if (IsPrimitiveCNode(node, prim::kPrimSwitch)) {
|
||||
auto switch_cnode_user_iter = node_users.find(node);
|
||||
if (switch_cnode_user_iter != node_users.end()) {
|
||||
ASSERT_EQ(switch_cnode_user_iter->second.size(), 1);
|
||||
auto switch_cnode_user = switch_cnode_user_iter->second.front().first;
|
||||
switch_cnodes_user.push_back(switch_cnode_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if the switch_cnode_user is used by GetItem call or FuncGraph call.
|
||||
for (const auto &switch_cnode_user : switch_cnodes_user) {
|
||||
auto user_iter = node_users.find(switch_cnode_user);
|
||||
if (user_iter != node_users.end()) {
|
||||
ASSERT_GE(user_iter->second.size(), 1);
|
||||
auto user = user_iter->second.front().first;
|
||||
if (IsPrimitiveCNode(user, prim::kPrimTupleGetItem)) {
|
||||
count++;
|
||||
} else if (GetCNodeFuncGraph(user) != nullptr) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(count, expected_count);
|
||||
}
|
||||
|
||||
public:
|
||||
UT::PyFuncGraphFetcher getPyFun;
|
||||
opt::irpass::OptimizeIRPassLib irpass_lib_;
|
||||
|
@ -106,5 +144,544 @@ TEST_F(TestParallelIf, IfInIf) { CheckParallelIfTransform("test_if_in_if"); }
|
|||
// Description: Check parallel if transformatin for test code with if-elif-else.
|
||||
// Expectation: The funcgraph after transformation should be isomorphic with the funcgraph manually constructed.
|
||||
TEST_F(TestParallelIf, IfElifElse) { CheckParallelIfTransform("test_if_elif_else"); }
|
||||
|
||||
// Return statement section.
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while return).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileReturnInElse) { CheckParallelIfTransformationCount("test_while_return_in_else", 0); }
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if return/else break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnElseBreakInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_else_break_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if return/else return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnElseReturnInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_else_return_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileReturnInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_while_return_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(if return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnInWhileInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_in_while_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(if return/else return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnElseReturnInWhileInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_else_return_in_while_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if/else by while(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileReturnAfterIfElseInElse) {
|
||||
CheckParallelIfTransformationCount("test_while_return_after_if_else_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(return) by if/else).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterWhileReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_while_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if/else by if(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnAfterIfElseInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_after_if_else_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if(return) by if/else).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterIfReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_if_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else by if/else(while(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileReturnInElseAfterIfElse) {
|
||||
CheckParallelIfTransformationCount("test_while_return_in_else_after_if_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(return)) by if/else.
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterByWhileReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_by_while_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else by if/else(if(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnInElseAfterIfElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_in_else_after_if_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if(return)) by if/else.
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterByIfReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_by_if_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if(if/else)/else(while(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseInIfWhileReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_in_if_while_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if(if/else)/else(if(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseInIfIfReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_in_if_if_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for return).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForReturnInElse) { CheckParallelIfTransformationCount("test_for_return_in_else", 0); }
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if return/else break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnElseBreakInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_else_break_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if return/else return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnElseReturnInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_else_return_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForReturnInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_for_return_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(if return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnInForInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_in_for_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(if return/else return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnElseReturnInForInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_else_return_in_for_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if/else by for(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForReturnAfterIfElseInElse) {
|
||||
CheckParallelIfTransformationCount("test_for_return_after_if_else_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(return) by if/else).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterForReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_for_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else by if/else(for(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForReturnInElseAfterIfElse) {
|
||||
CheckParallelIfTransformationCount("test_for_return_in_else_after_if_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(return)) by if/else.
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterByForReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_by_for_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if(if/else)/else(for(return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseInIfForReturnInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_in_if_for_return_in_else", 1);
|
||||
}
|
||||
|
||||
// Break statement section.
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while break).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileBreakInElse) { CheckParallelIfTransformationCount("test_while_break_in_else", 1); }
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_in_while_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if break/else break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakElseBreakInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_else_break_in_while_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if break/else return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakElseReturnInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_else_return_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(break))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileBreakInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_while_break_in_while_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(if break))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakInWhileInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_in_while_in_while_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(if break/else return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakElseReturnInWhileInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_else_return_in_while_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if/else by while(break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileBreakAfterIfElseInElse) {
|
||||
CheckParallelIfTransformationCount("test_while_break_after_if_else_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(break) by if/else).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterWhileBreakInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_while_break_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else by if/else(while(break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileBreakInElseAfterIfElse) {
|
||||
CheckParallelIfTransformationCount("test_while_break_in_else_after_if_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(break)) by if/else.
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterByWhileBreakInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_by_while_break_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if(if/else)/else(while(break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseInIfWhileBreakInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_in_if_while_break_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for break).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForBreakInElse) { CheckParallelIfTransformationCount("test_for_break_in_else", 1); }
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_in_for_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if break/else return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakElseReturnInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_else_return_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if break/else break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakElseBreakInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_else_break_in_for_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(break))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForBreakInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_for_break_in_for_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(if break))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakInForInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_in_for_in_for_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(if break/else return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfBreakElseReturnInForInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_break_else_return_in_for_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if/else by for(break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForBreakAfterIfElseInElse) {
|
||||
CheckParallelIfTransformationCount("test_for_break_after_if_else_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(break) by if/else).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterForBreakInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_for_break_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else by if/else(for(break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForBreakInElseAfterIfElse) {
|
||||
CheckParallelIfTransformationCount("test_for_break_in_else_after_if_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(break)) by if/else.
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterByForBreakInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_by_for_break_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if(if/else)/else(for(break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseInIfForBreakInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_in_if_for_break_in_else", 2);
|
||||
}
|
||||
|
||||
// Continue statement section
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while continue).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileContinueInElse) {
|
||||
CheckParallelIfTransformationCount("test_while_continue_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_in_while_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if continue/else continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueElseContinueInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_else_continue_in_while_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(if continue/else return)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueElseReturnInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_else_return_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(continue))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileContinueInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_while_continue_in_while_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(if continue))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueInWhileInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_in_while_in_while_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(while(if continue/else return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueElseReturnInWhileInWhileInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_else_return_in_while_in_while_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if/else by while(continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileContinueAfterIfElseInElse) {
|
||||
CheckParallelIfTransformationCount("test_while_continue_after_if_else_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(continue) by if/else).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterWhileContinueInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_while_continue_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else by if/else(while(continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountWhileContinueInElseAfterIfElse) {
|
||||
CheckParallelIfTransformationCount("test_while_continue_in_else_after_if_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(while(continue)) by if/else.
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterByWhileContinueInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_by_while_continue_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if(if/else)/else(while(continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseInIfWhileContinueInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_in_if_while_continue_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for continue).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForContinueInElse) { CheckParallelIfTransformationCount("test_for_continue_in_else", 1); }
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_in_for_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if return/else continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfReturnElseContinueInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_return_else_continue_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(if continue/else continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueElseContinueInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_else_continue_in_for_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(continue))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForContinueInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_for_continue_in_for_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(if continue))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueInForInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_in_for_in_for_in_else", 1);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(for(if continue/else return))).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfContinueElseReturnInForInForInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_continue_else_return_in_for_in_for_in_else", 0);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(if/else by for(continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForContinueAfterIfElseInElse) {
|
||||
CheckParallelIfTransformationCount("test_for_continue_after_if_else_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(continue) by if/else).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterForContinueInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_for_continue_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else by if/else(for(continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountForContinueInElseAfterIfElse) {
|
||||
CheckParallelIfTransformationCount("test_for_continue_in_else_after_if_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if/else(for(continue)) by if/else.
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseAfterByForContinueInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_after_by_for_continue_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if(if/else)/else(for(continue)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountIfElseInIfForContinueInElse) {
|
||||
CheckParallelIfTransformationCount("test_if_else_in_if_for_continue_in_else", 2);
|
||||
}
|
||||
|
||||
// Feature: Parallel if transformation
|
||||
// Description: Check parallel if transformatin for if(func call)/else(while(break)).
|
||||
// Expectation: The count of parallel if transformation should be equal to the expected count.
|
||||
TEST_F(TestParallelIf, CountFuncCallInIfWhileBreakInElse) {
|
||||
CheckParallelIfTransformationCount("test_func_call_in_if_while_break_in_else", 1);
|
||||
}
|
||||
} // namespace parse
|
||||
} // namespace mindspore
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue