From 3f47e1bc84217041b97b00d1c2a96cb655b74821 Mon Sep 17 00:00:00 2001 From: chenlei_autodiff Date: Mon, 7 Jun 2021 09:30:06 +0800 Subject: [PATCH] [GraphKernel] fix bgcf and enbale graph kernel. --- .../graph_kernel/graph_kernel_helper.cc | 35 ++++--------------- model_zoo/official/gnn/bgcf/train.py | 2 ++ 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc b/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc index d15790cf47f..0912537257d 100644 --- a/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc +++ b/mindspore/ccsrc/backend/optimizer/graph_kernel/graph_kernel_helper.cc @@ -126,25 +126,6 @@ bool GenJson(const AnfNodePtrList &op_nodes, const std::pairDataSize() == 1) { - return true; - } - - auto data = static_cast(tensor->data_c()); - auto itemsize = static_cast(tensor->data().itemsize()); - 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]) { - return false; - } - } - } - return true; -} - AnfNodePtr ConvertToScalarTensor(const AnfNodePtr &value_node) { auto tensor = GetValueNode(value_node); MS_EXCEPTION_IF_NULL(tensor); @@ -222,17 +203,13 @@ bool ConvertNonscalarTensorToParameter(const FuncGraphPtr &fg, AnfNodePtrList *i if (tensor == nullptr || tensor->DataSize() == 1) { continue; } - if (TensorElementAllTheSame(tensor)) { - scalar_tensors.emplace_back(tnode); + auto tensor_iter = std::find_if( + v_replace.begin(), v_replace.end(), + [&tensor](const std::pair &vl) { return vl.first->ValueEqual(*tensor); }); + if (tensor_iter == v_replace.end()) { + v_replace.emplace_back(tensor, AnfNodePtrList{tnode}); } else { - auto tensor_iter = std::find_if( - v_replace.begin(), v_replace.end(), - [&tensor](const std::pair &vl) { return vl.first->ValueEqual(*tensor); }); - if (tensor_iter == v_replace.end()) { - v_replace.emplace_back(tensor, AnfNodePtrList{tnode}); - } else { - tensor_iter->second.push_back(tnode); - } + tensor_iter->second.push_back(tnode); } } } diff --git a/model_zoo/official/gnn/bgcf/train.py b/model_zoo/official/gnn/bgcf/train.py index 61bedf96f17..4726bb774f6 100644 --- a/model_zoo/official/gnn/bgcf/train.py +++ b/model_zoo/official/gnn/bgcf/train.py @@ -101,6 +101,8 @@ def run_train(): if config.device_target == "Ascend": context.set_context(device_id=get_device_id()) + if config.device_target == "GPU": + context.set_context(enable_graph_kernel=True) train_graph, _, sampled_graph_list = load_graph(config.datapath) train_ds = create_dataset(train_graph, sampled_graph_list, config.workers, batch_size=config.batch_pairs,