Browse Source

fix static code check

tags/v1.3.0
huanghui 4 years ago
parent
commit
197bd84ae0
10 changed files with 23 additions and 39 deletions
  1. +2
    -0
      mindspore/_extends/parse/trope.py
  2. +2
    -0
      mindspore/_extends/utils.py
  3. +10
    -29
      mindspore/ccsrc/frontend/operator/prim_to_function.cc
  4. +1
    -1
      mindspore/ccsrc/pipeline/jit/parse/function_block.cc
  5. +1
    -2
      mindspore/ccsrc/pipeline/jit/pass.cc
  6. +2
    -1
      mindspore/core/abstract/abstract_value.cc
  7. +1
    -1
      mindspore/core/abstract/prim_arrays.cc
  8. +1
    -1
      mindspore/core/ir/func_graph_extends.cc
  9. +0
    -1
      mindspore/core/ir/manager.cc
  10. +3
    -3
      mindspore/core/utils/profile.cc

+ 2
- 0
mindspore/_extends/parse/trope.py View File

@@ -92,10 +92,12 @@ def not_contains(x): # pragma: no cover
"""Not in function."""
raise RuntimeError('This operation is not meant to be called directly.')


def while_cond(x): # pragma: no cover
"""Not in function."""
raise RuntimeError('This operation is not meant to be called directly.')


def bool_(x): # pragma: no cover
"""judge true function."""
raise RuntimeError('This operation is not meant to be called directly.')

+ 2
- 0
mindspore/_extends/utils.py View File

@@ -17,6 +17,7 @@
import inspect
from functools import wraps


def cell_attr_register(fn=None, attrs=None):
"""
Cell init attributes register.
@@ -31,6 +32,7 @@ def cell_attr_register(fn=None, attrs=None):
Returns:
function, original function.
"""

def wrap_cell(fn):
@wraps(fn)
def deco(self, *args, **kwargs):


+ 10
- 29
mindspore/ccsrc/frontend/operator/prim_to_function.cc View File

@@ -22,35 +22,16 @@ namespace mindspore {
namespace prim {

PrimToFunction::PrimToFunction()
: prim_func_type_map_({// ONE_ARG prim
{"bool_not", kPrimTypeOneArg},
{"scalar_cos", kPrimTypeOneArg},
{"scalar_exp", kPrimTypeOneArg},
{kScalarFloor, kPrimTypeOneArg},
{"scalar_log", kPrimTypeOneArg},
{"scalar_sin", kPrimTypeOneArg},
{"scalar_tan", kPrimTypeOneArg},
{kScalarTrunc, kPrimTypeOneArg},
{"typeof", kPrimTypeOneArg},
{kScalarUadd, kPrimTypeOneArg},
{kScalarUsub, kPrimTypeOneArg},
// TWO_ARGS prim
{kScalarAdd, kPrimTypeTwoArgs},
{"bool_and", kPrimTypeTwoArgs},
{"bool_eq", kPrimTypeTwoArgs},
{"bool_or", kPrimTypeTwoArgs},
{kScalarDiv, kPrimTypeTwoArgs},
{"scalar_eq", kPrimTypeTwoArgs},
{"scalar_ge", kPrimTypeTwoArgs},
{"scalar_gt", kPrimTypeTwoArgs},
{"scalar_le", kPrimTypeTwoArgs},
{"scalar_lt", kPrimTypeTwoArgs},
{"scalar_ne", kPrimTypeTwoArgs},
{kScalarMod, kPrimTypeTwoArgs},
{kScalarMul, kPrimTypeTwoArgs},
{kScalarPow, kPrimTypeTwoArgs},
{kScalarSub, kPrimTypeTwoArgs},
{kScalarFloordiv, kPrimTypeTwoArgs}}) {}
: prim_func_type_map_(
{{"bool_not", kPrimTypeOneArg}, {"scalar_cos", kPrimTypeOneArg}, {"scalar_exp", kPrimTypeOneArg},
{kScalarFloor, kPrimTypeOneArg}, {"scalar_log", kPrimTypeOneArg}, {"scalar_sin", kPrimTypeOneArg},
{"scalar_tan", kPrimTypeOneArg}, {kScalarTrunc, kPrimTypeOneArg}, {"typeof", kPrimTypeOneArg},
{kScalarUadd, kPrimTypeOneArg}, {kScalarUsub, kPrimTypeOneArg}, {kScalarAdd, kPrimTypeTwoArgs},
{"bool_and", kPrimTypeTwoArgs}, {"bool_eq", kPrimTypeTwoArgs}, {"bool_or", kPrimTypeTwoArgs},
{kScalarDiv, kPrimTypeTwoArgs}, {"scalar_eq", kPrimTypeTwoArgs}, {"scalar_ge", kPrimTypeTwoArgs},
{"scalar_gt", kPrimTypeTwoArgs}, {"scalar_le", kPrimTypeTwoArgs}, {"scalar_lt", kPrimTypeTwoArgs},
{"scalar_ne", kPrimTypeTwoArgs}, {kScalarMod, kPrimTypeTwoArgs}, {kScalarMul, kPrimTypeTwoArgs},
{kScalarPow, kPrimTypeTwoArgs}, {kScalarSub, kPrimTypeTwoArgs}, {kScalarFloordiv, kPrimTypeTwoArgs}}) {}

bool PrimToFunction::GetFunction(const PrimitivePtr &prim, FunctionPtr *const func) const {
bool result = false;


+ 1
- 1
mindspore/ccsrc/pipeline/jit/parse/function_block.cc View File

@@ -261,7 +261,7 @@ 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.
// phi : This parameter node is functioning as a phi node.
// Args: phi: This parameter node is functioning as a phi node.
bool FunctionBlock::CollectRemovablePhi(const ParameterPtr &phi) {
MS_EXCEPTION_IF_NULL(phi);
std::string var = phi_nodes_[phi];


+ 1
- 2
mindspore/ccsrc/pipeline/jit/pass.cc View File

@@ -366,8 +366,7 @@ OptPassGroupMap GetOptPassesAfterCconv(const opt::irpass::OptimizeIRPassLib &irp

OptPassGroupMap GetOptPassesTransformGraph(const opt::irpass::OptimizeIRPassLib &irpass) {
opt::OptPassConfig d_1 =
opt::OptPassConfig({// Safe inlining
irpass.call_graph_tuple_transform_, irpass.tuple_list_get_item_eliminator_,
opt::OptPassConfig({irpass.call_graph_tuple_transform_, irpass.tuple_list_get_item_eliminator_,
irpass.tuple_list_get_item_const_eliminator_, irpass.tuple_list_set_item_eliminator_,
irpass.tuple_list_get_set_item_eliminator_, irpass.tuple_list_get_item_depend_reorder_,
irpass.tuple_list_convert_item_index_to_positive_});


+ 2
- 1
mindspore/core/abstract/abstract_value.cc View File

@@ -290,7 +290,8 @@ std::size_t AbstractSequeue::hash() const {
std::size_t hash_sum = hash_combine(tid(), std::hash<size_t>{}(elements_.size()));
// Hashing all elements is costly, so only take at most 4 elements into account based on
// some experiments.
for (size_t i = 0; (i < elements_.size()) && (i < 4); i++) {
size_t max_elements_cnt = 4;
for (size_t i = 0; (i < elements_.size()) && (i < max_elements_cnt); i++) {
hash_sum = hash_combine(hash_sum, elements_[i]->hash());
}
return hash_sum;


+ 1
- 1
mindspore/core/abstract/prim_arrays.cc View File

@@ -611,7 +611,7 @@ AbstractBasePtr InferImplGatherV2(const AnalysisEnginePtr &, const PrimitivePtr
ShapeVector indices_shp_min = (ind_dyn) ? indices->shape()->min_shape() : indices->shape()->shape();
ShapeVector indices_shp_max = (ind_dyn) ? indices->shape()->max_shape() : indices->shape()->shape();
// check axis_val within interval: [-params_rank, params_rank)
if (!(-params_rank <= axis_val) || !(axis_val < params_rank)) {
if (-params_rank > axis_val || axis_val >= params_rank) {
MS_LOG(EXCEPTION) << "For Gather - Axis value must be within [ " << -params_rank << ", " << params_rank << " ) "
<< "Got " << axis_val << ".";
}


+ 1
- 1
mindspore/core/ir/func_graph_extends.cc View File

@@ -47,7 +47,7 @@ AbstractFunctionPtr FuncGraph::abstract() {
args_spec_list.push_back(p->abstract());
}

if (nullptr == output()) {
if (output() == nullptr) {
MS_LOG(ERROR) << "Error func graph no output";
return nullptr;
}


+ 0
- 1
mindspore/core/ir/manager.cc View File

@@ -295,7 +295,6 @@ void FuncGraphManager::AddIntoManaged(const FuncGraphPtr &fg) {
void FuncGraphManager::MaybeDropFuncGraphs(const FuncGraphSet &func_graphs, bool ignore_users) {
FuncGraphSet todo(func_graphs);
std::set<FuncGraphPtr> dropped;
// int count = 0;
while (!todo.empty()) {
FuncGraphPtr func_graph = todo.pop();
MS_EXCEPTION_IF_NULL(func_graph);


+ 3
- 3
mindspore/core/utils/profile.cc View File

@@ -110,7 +110,7 @@ void PrintProfile(std::ostringstream &oss, const TimeInfo &time_info, int indent
}
oss << " " << std::left << std::setw(36) << name << " : " << std::right << std::setw(12) << std::fixed
<< std::setprecision(6) << iter.second << "s : " << std::right << std::setw(5) << std::fixed
<< std::setprecision(2) << iter.second / total * 100 << "%\n";
<< std::setprecision(2) << (iter.second / total) * 100 << "%\n";
}
}
delete sums;
@@ -157,7 +157,7 @@ void Profile::Print(void) {
std::ostringstream oss;
PrintProfile(oss, *ctx_ptr_->time_info_);
std::string text = oss.str();
// here use printf to output profile info, not use MS_LOG(INFO) since when open log, it affects performace
// here use printf to output profile info, not use MS_LOG(INFO) since when open log, it affects performance
(void)printf("%s", text.c_str());
(void)fflush(stdout);
}
@@ -357,7 +357,7 @@ void MsProfile::Print() {
PrintTimeStat(oss, groups[i], prefix);
}
std::string text = oss.str();
// here use printf to output profile info, not use MS_LOG(INFO) since when open log, it affects performace
// here use printf to output profile info, not use MS_LOG(INFO) since when open log, it affects performance
(void)printf("\nTime group info:\n%s", text.c_str());
(void)fflush(stdout);
}


Loading…
Cancel
Save