forked from mindspore-Ecosystem/mindspore
!16841 code check
From: @Margaret_wangrui Reviewed-by: @zh_qh,@ginfung Signed-off-by: @zh_qh
This commit is contained in:
commit
e4c065b53f
|
@ -812,7 +812,8 @@ std::vector<AnfNodePtr> SessionBasic::CreateCallSwitchInputs(const CNodePtr &cno
|
|||
auto cnode_input = graph->GetBackendAnfByFrontAnf(attr_input);
|
||||
auto switch_cnode = cnode_input->cast<CNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(switch_cnode);
|
||||
if (cnode->inputs().size() < 2) {
|
||||
constexpr size_t cnode_size = 2;
|
||||
if (cnode->inputs().size() < cnode_size) {
|
||||
cnode_inputs = switch_cnode->inputs();
|
||||
return cnode_inputs;
|
||||
}
|
||||
|
|
|
@ -951,7 +951,8 @@ FuncGraphPtr TupleSlice::GenerateFuncGraph(const AbstractBasePtrList &args_spec_
|
|||
// slice a tuple
|
||||
// args: tuple, start index, end index, step
|
||||
const std::string op_name("TupleSlice");
|
||||
abstract::CheckArgsSize(op_name, args_spec_list, 2);
|
||||
constexpr size_t arg_size = 2;
|
||||
abstract::CheckArgsSize(op_name, args_spec_list, arg_size);
|
||||
AbstractTuplePtr tuple = abstract::CheckArg<AbstractTuple>(op_name, args_spec_list, 0);
|
||||
AbstractSlicePtr slice = abstract::CheckArg<AbstractSlice>(op_name, args_spec_list, 1);
|
||||
|
||||
|
|
|
@ -342,7 +342,8 @@ AbstractBasePtr InferImplReduceShape(const AnalysisEnginePtr &, const PrimitiveP
|
|||
const AbstractBasePtrList &args_spec_list) {
|
||||
// Inputs: x_shape, axis
|
||||
const std::string op_name = primitive->name();
|
||||
CheckArgsSize(op_name, args_spec_list, 2);
|
||||
constexpr size_t arg_size = 2;
|
||||
CheckArgsSize(op_name, args_spec_list, arg_size);
|
||||
AbstractTuplePtr shape_x = CheckArg<AbstractTuple>(op_name, args_spec_list, 0);
|
||||
MS_EXCEPTION_IF_NULL(args_spec_list[1]);
|
||||
|
||||
|
@ -381,7 +382,8 @@ AbstractBasePtr InferImplTupleDiv(const AnalysisEnginePtr &, const PrimitivePtr
|
|||
const AbstractBasePtrList &args_spec_list) {
|
||||
// Inputs: two tuples.
|
||||
const std::string op_name = primitive->name();
|
||||
CheckArgsSize(op_name, args_spec_list, 2);
|
||||
constexpr size_t arg_size = 2;
|
||||
CheckArgsSize(op_name, args_spec_list, arg_size);
|
||||
AbstractTuplePtr shape_x = CheckArg<AbstractTuple>(op_name, args_spec_list, 0);
|
||||
AbstractTuplePtr div_shp = CheckArg<AbstractTuple>(op_name, args_spec_list, 1);
|
||||
MS_LOG(INFO) << "DivShape input:" << shape_x->ToString() << ", div:" << div_shp->ToString();
|
||||
|
|
|
@ -98,9 +98,10 @@ AnfNodePtr ConvertGetAttrToTupleGetItem(const CNodePtr &node) {
|
|||
const auto &inputs = node->inputs();
|
||||
// Inputs should be [getattr, data, attribute]
|
||||
MS_ASSERT(inputs.size() == 3 && "GetAttr should have three inputs.");
|
||||
|
||||
AnfNodePtr data = inputs[1];
|
||||
AnfNodePtr cons = inputs[2];
|
||||
constexpr size_t data_index = 1;
|
||||
constexpr size_t attribute_index = 2;
|
||||
AnfNodePtr data = inputs[data_index];
|
||||
AnfNodePtr cons = inputs[attribute_index];
|
||||
MS_EXCEPTION_IF_NULL(data);
|
||||
MS_EXCEPTION_IF_NULL(cons);
|
||||
|
||||
|
@ -140,9 +141,10 @@ AnfNodePtr ConvertDictGetItemToTupleGetItem(const CNodePtr &node) {
|
|||
// Inputs should be [dict_getitem, dict, item]
|
||||
const auto &inputs = node->inputs();
|
||||
MS_ASSERT(inputs.size() == 3 && "DictGetItem should have three inputs.");
|
||||
|
||||
AnfNodePtr data = inputs[1];
|
||||
AnfNodePtr cons = inputs[2];
|
||||
constexpr size_t data_index = 1;
|
||||
constexpr size_t cons_index = 2;
|
||||
AnfNodePtr data = inputs[data_index];
|
||||
AnfNodePtr cons = inputs[cons_index];
|
||||
MS_EXCEPTION_IF_NULL(data);
|
||||
MS_EXCEPTION_IF_NULL(cons);
|
||||
|
||||
|
@ -334,7 +336,8 @@ AnfNodePtr EraseExtractKeywordArg(const CNodePtr &node) {
|
|||
const auto &inputs = node->inputs();
|
||||
// Inputs should be [extract_keyword_arg, arg, key]
|
||||
MS_ASSERT(inputs.size() == 3 && "ExtractKeyword should have three inputs");
|
||||
return inputs[2];
|
||||
constexpr size_t key_index = 2;
|
||||
return inputs[key_index];
|
||||
}
|
||||
|
||||
ValueTuplePtr ConvertValueListToValueTuple(const ValueListPtr &value_list, int64_t depth) {
|
||||
|
@ -575,7 +578,8 @@ static std::vector<AnfNodePtr> ExpandTuplesC(const FuncGraphPtr &graph, const st
|
|||
for (auto &elem : abs_tuple->elements()) {
|
||||
auto c_node = graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), input, NewValueNode(idx)});
|
||||
AbstractBasePtr aptr = std::make_shared<AbstractScalar>(std::make_shared<Int64Imm>(idx));
|
||||
c_node->input(2)->set_abstract(aptr);
|
||||
constexpr size_t scalar_index = 2;
|
||||
c_node->input(scalar_index)->set_abstract(aptr);
|
||||
c_node->set_abstract(elem);
|
||||
new_input.emplace_back(c_node);
|
||||
idx++;
|
||||
|
|
|
@ -99,7 +99,8 @@ void TwoCastEliminater::Visit(const AnfNodePtr &node) {
|
|||
if (IsPrimitiveCNode(node, prim::kPrimCast)) {
|
||||
auto cnode = node->cast<CNodePtr>();
|
||||
// {prim::kPrimCast, X, Y}
|
||||
if (cnode->size() != 3) {
|
||||
constexpr size_t cast_size = 3;
|
||||
if (cnode->size() != cast_size) {
|
||||
return;
|
||||
}
|
||||
x_ = cnode->input(1);
|
||||
|
|
|
@ -261,7 +261,6 @@ AnfNodePtr FunctionBlock::SearchReplaceNode(const std::string &var, const Parame
|
|||
// 1. when this function is called, not all usage of this phi node had bound to the
|
||||
// graph of this function block, some may stay in vars_ in other blocks.
|
||||
// 2. it's costly to iterate the graph to replace the phi for each phi.
|
||||
// Args :
|
||||
// phi : This parameter node is functioning as a phi node.
|
||||
bool FunctionBlock::CollectRemovablePhi(const ParameterPtr &phi) {
|
||||
MS_EXCEPTION_IF_NULL(phi);
|
||||
|
|
|
@ -411,7 +411,8 @@ FunctionBlockPtr Parser::ParseExpr(const FunctionBlockPtr &block, const py::obje
|
|||
LocationPtr Parser::GetLocation(const py::object &node) const {
|
||||
MS_EXCEPTION_IF_NULL(ast_);
|
||||
py::list ret = ast_->CallParserObjMethod(PYTHON_PARSE_GET_LOCATION, node);
|
||||
if (ret.size() < 5) {
|
||||
constexpr size_t list_size = 5;
|
||||
if (ret.size() < list_size) {
|
||||
MS_LOG(EXCEPTION) << "List size should not be less than 5.";
|
||||
}
|
||||
// Refer to Location::Location() for each member of ret: line, column, line_end, column_end.
|
||||
|
|
|
@ -189,7 +189,8 @@ py::tuple GenerateKey(const std::string &name, const std::unordered_map<std::str
|
|||
MS_LOG(INFO) << "Start new args and compile key:" << key;
|
||||
g_args_cache[args_spec] = key++;
|
||||
}
|
||||
auto argSpec = py::tuple(2);
|
||||
constexpr size_t arg_size = 2;
|
||||
auto argSpec = py::tuple(arg_size);
|
||||
argSpec[0] = name;
|
||||
argSpec[1] = g_args_cache[args_spec];
|
||||
return argSpec;
|
||||
|
|
|
@ -260,7 +260,9 @@ EvalResultPtr MixedPrecisionCastEvaluator::Run(AnalysisEnginePtr engine, const C
|
|||
ScopeGuard scope_guard(scope);
|
||||
|
||||
FuncGraphPtr func_graph = out_conf->node()->func_graph();
|
||||
AnfNodePtr new_node = MixedPrecisionCastHelper(out_node_inputs[2], args_spec_list[1], out_node_inputs[1], func_graph);
|
||||
constexpr size_t source_node_index = 2;
|
||||
AnfNodePtr new_node =
|
||||
MixedPrecisionCastHelper(out_node_inputs[source_node_index], args_spec_list[1], out_node_inputs[1], func_graph);
|
||||
AnfNodeConfigPtr fn_conf = engine->MakeConfig(new_node, out_conf->context());
|
||||
|
||||
if (new_node->isa<CNode>()) {
|
||||
|
|
|
@ -402,8 +402,7 @@ AnfNodePtr FuncGraphSpecializer::BuildSpecializedNodeInner(const AnfNodePtr &nod
|
|||
return BuildValueNode(real_func->prim(), abs);
|
||||
}
|
||||
|
||||
EvaluatorPtr eval;
|
||||
eval = engine_->GetEvaluatorFor(func);
|
||||
EvaluatorPtr eval = engine_->GetEvaluatorFor(func);
|
||||
MS_EXCEPTION_IF_NULL(eval);
|
||||
AbstractBasePtrList argvals = eval->NormalizeArgs(args);
|
||||
|
||||
|
|
Loading…
Reference in New Issue