Browse Source

fix static check problems

tags/v1.3.0
dayschan 5 years ago
parent
commit
dabc0db9c2
3 changed files with 12 additions and 16 deletions
  1. +1
    -2
      mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_expander.cc
  2. +10
    -13
      mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc
  3. +1
    -1
      mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.h

+ 1
- 2
mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_expander.cc View File

@@ -119,8 +119,7 @@ FuncGraphPtr DefaultExpander::CreateExpandFuncGraph(const CNodePtr &node) {
return nullptr;
}
// decode json to func_graph.
std::vector<AnfNodePtr> ori_inputs(node->inputs().begin() + 1, node->inputs().end());
return JsonDescToAnf(kernel_desc_str, ori_inputs);
return JsonDescToAnf(kernel_desc_str);
}

void DefaultExpander::EliminateRedundantParameters(const FuncGraphPtr &func_graph, AnfNodePtrList *inputs) {


+ 10
- 13
mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc View File

@@ -134,7 +134,7 @@ bool TensorElementAllTheSame(const tensor::TensorPtr &tensor) {

auto data = static_cast<char *>(tensor->data_c());
auto itemsize = static_cast<size_t>(tensor->data().itemsize());
auto total_cnt = static_cast<size_t>(tensor->DataSize());
auto total_cnt = IntToSize(tensor->DataSize());
for (size_t i = 1; i < total_cnt; ++i) {
for (size_t ei = 0; ei < itemsize; ++ei) {
if (data[ei] != data[i * itemsize + ei]) {
@@ -150,7 +150,7 @@ AnfNodePtr ConvertToScalarTensor(const AnfNodePtr &value_node) {
MS_EXCEPTION_IF_NULL(tensor);
auto type_id = tensor->data_type();
ShapeVector new_shape;
auto origin_ndim = static_cast<size_t>(tensor->DataDim());
auto origin_ndim = IntToSize(tensor->DataDim());
for (size_t i = 0; i < origin_ndim; ++i) {
new_shape.push_back(1);
}
@@ -429,7 +429,7 @@ void ReplaceNewFuseCNode(const FuncGraphPtr &func_graph, const AnfNodePtr &new_f
auto value_node = value_input->cast<ValueNodePtr>();
MS_EXCEPTION_IF_NULL(value_node);
auto item_idx = GetValue<int64_t>(value_node->value());
int64_t new_item_idx = SizeToLong(out_idx) + offset + item_idx;
int64_t new_item_idx = SizeToLong(out_idx + offset) + item_idx;
fn_inputs.clear();
fn_inputs.push_back(NewValueNode(prim::kPrimTupleGetItem));
fn_inputs.push_back(new_fuse_cnode);
@@ -567,7 +567,7 @@ bool AnfToJsonDesc(const std::vector<AnfNodePtrList> &graphs, const DumpOption &
return true;
}

FuncGraphPtr JsonDescToAnf(const std::string &json_desc, const std::vector<AnfNodePtr> &inputs) {
FuncGraphPtr JsonDescToAnf(const std::string &json_desc) {
kernel::AkgKernelJsonDecoder akg_kernel_json_decoder;
auto fg = akg_kernel_json_decoder.DecodeFusedNodes(json_desc);
if (fg == nullptr) {
@@ -762,19 +762,16 @@ bool IsKeepBasicNode(const AnfNodePtr &node) {
auto cnode = node->cast<CNodePtr>();
MS_EXCEPTION_IF_NULL(cnode);

static std::vector<std::string> contagious_attrs = {"inplace_group", "inplace_algo", "inplace_output_index",
"aggregate", "aggregate_input_indexx"};
static std::vector<std::function<bool(const AnfNodePtr &node)>> attrs_with_value = {
[](const AnfNodePtr &n) -> bool { return AnfAlgo::GetBooleanAttr(n, "skip"); }};
static const std::vector<std::string> contagious_attrs = {"inplace_group", "inplace_algo", "inplace_output_index",
"aggregate", "aggregate_input_indexx"};
// If node contain attribute in contagious_attrs, it have to keep basic no matter what the value is.
// If node contain attribute in attrs_with_value, it only have to keep basic when the check result is true.
if (std::any_of(contagious_attrs.cbegin(), contagious_attrs.cend(),
[&cnode](const std::string &attr_name) -> bool { return AnfAlgo::HasNodeAttr(attr_name, cnode); }) ||
std::any_of(attrs_with_value.cbegin(), attrs_with_value.cend(),
[&cnode](std::function<bool(const AnfNodePtr &node)> func) -> bool { return func(cnode); })) {
[&cnode](const std::string &attr_name) -> bool { return AnfAlgo::HasNodeAttr(attr_name, cnode); })) {
return true;
}
if (AnfAlgo::GetBooleanAttr(cnode, "skip")) {
return true;
}

return false;
}



+ 1
- 1
mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.h View File

@@ -75,7 +75,7 @@ bool AnfToJsonDesc(const AnfNodePtrList &nodes, const DumpOption &dump_option, n
bool AnfToJsonDesc(const AnfNodePtrList &nodes, const DumpOption &dump_option, nlohmann::json *op_desc,
std::map<std::string, AnfNodePtr> *address_node_map);
bool AnfToJsonDesc(const std::vector<AnfNodePtrList> &graphs, const DumpOption &dump_option, nlohmann::json *op_desc);
FuncGraphPtr JsonDescToAnf(const std::string &json_desc, const std::vector<AnfNodePtr> &inputs);
FuncGraphPtr JsonDescToAnf(const std::string &json_desc);
std::string ExtractGraphKernelName(const AnfNodePtrList &cnodes, const string &prefix = "", const string &postfix = "");
void ResetKernelInfo(const AnfNodePtr &node, KernelType kernel_type = KernelType::UNKNOWN_KERNEL_TYPE);



Loading…
Cancel
Save