diff --git a/mindspore/ccsrc/backend/session/ascend_session.cc b/mindspore/ccsrc/backend/session/ascend_session.cc index b3ce93cc285..b844af4866c 100644 --- a/mindspore/ccsrc/backend/session/ascend_session.cc +++ b/mindspore/ccsrc/backend/session/ascend_session.cc @@ -204,7 +204,9 @@ void GenOpOutputStubTensor(const KernelGraphPtr &single_op_graph, const CNodePtr std::make_shared(nullptr, 0, output_format, output_type); stub_output_tensor->set_device_address(device_address); output_tensor_info.output_stub_tensor = stub_output_tensor; - output_tensor_info.is_weight = !dynamic_cast(output_node->kernel_info())->is_feature_map(); + auto kernel_info = dynamic_cast(output_node->kernel_info()); + MS_EXCEPTION_IF_NULL(kernel_info); + output_tensor_info.is_weight = !(kernel_info->is_feature_map()); (*op_output_info)[kernel_with_index] = output_tensor_info; } } diff --git a/mindspore/ccsrc/backend/session/cpu_session.cc b/mindspore/ccsrc/backend/session/cpu_session.cc index 56dadf54200..8f6042025d8 100644 --- a/mindspore/ccsrc/backend/session/cpu_session.cc +++ b/mindspore/ccsrc/backend/session/cpu_session.cc @@ -128,15 +128,6 @@ void CPUSession::CreateOutputTensors(const GraphId &graph_id, const std::vector< runtime_.CreateOutputTensors(kernel_graph.get(), input_tensors, outputs, tensor_to_node); } -void CPUSession::SyncValueNodeDeviceAddr(const std::shared_ptr &kernel_graph) { - auto context_ptr = MsContext::GetInstance(); - MS_EXCEPTION_IF_NULL(context_ptr); - if (context_ptr->get_param(MS_CTX_EXECUTION_MODE) != kPynativeMode) { - return; - } - runtime_.SyncValueNodeDeviceAddr(kernel_graph.get()); -} - void CPUSession::LoadInputData(const std::shared_ptr &kernel_graph, const std::vector &inputs_const) const { MS_EXCEPTION_IF_NULL(kernel_graph); @@ -167,7 +158,6 @@ void CPUSession::RunGraphImpl(const GraphId &graph_id, const std::vector *outputs_tensors); - void SyncValueNodeDeviceAddr(const std::shared_ptr &kernel_graph); device::cpu::CPUKernelRuntime runtime_; }; MS_REG_SESSION(kCPUDevice, CPUSession); diff --git a/mindspore/ccsrc/backend/session/gpu_session.cc b/mindspore/ccsrc/backend/session/gpu_session.cc index f3623489a7b..5f172d79d45 100644 --- a/mindspore/ccsrc/backend/session/gpu_session.cc +++ b/mindspore/ccsrc/backend/session/gpu_session.cc @@ -423,8 +423,6 @@ void GPUSession::RunGraphImpl(const GraphId &graph_id, const std::vectorPreExecute(kernel_graph, graph_sum_); } @@ -445,8 +443,6 @@ void GPUSession::RunGraphImpl(const GraphId &graph_id, const std::vector &kernel_gra } } -void GPUSession::SyncValueNodeDeviceAddr(const std::shared_ptr &kernel_graph) const { - auto context_ptr = MsContext::GetInstance(); - MS_EXCEPTION_IF_NULL(context_ptr); - if (context_ptr->get_param(MS_CTX_EXECUTION_MODE) != kPynativeMode) { - return; - } - auto runtime_instance = device::KernelRuntimeManager::Instance().GetSingleKernelRuntime(kGPUDevice, device_id_); - MS_EXCEPTION_IF_NULL(runtime_instance); - runtime_instance->SyncValueNodeDeviceAddr(kernel_graph.get()); -} - -void GPUSession::CleanValueNodeDeviceAddr(const std::shared_ptr &kernel_graph) const { - auto context_ptr = MsContext::GetInstance(); - MS_EXCEPTION_IF_NULL(context_ptr); - if (context_ptr->get_param(MS_CTX_EXECUTION_MODE) != kPynativeMode) { - return; - } - auto runtime_instance = device::KernelRuntimeManager::Instance().GetSingleKernelRuntime(kGPUDevice, device_id_); - MS_EXCEPTION_IF_NULL(runtime_instance); - runtime_instance->CleanValueNodeDeviceAddr(kernel_graph.get()); -} - void GPUSession::SyncStream() { auto runtime_instance = device::KernelRuntimeManager::Instance().GetSingleKernelRuntime(kGPUDevice, device_id_); MS_EXCEPTION_IF_NULL(runtime_instance); diff --git a/mindspore/ccsrc/backend/session/gpu_session.h b/mindspore/ccsrc/backend/session/gpu_session.h index 0cbf16c039a..76bfe454b1a 100644 --- a/mindspore/ccsrc/backend/session/gpu_session.h +++ b/mindspore/ccsrc/backend/session/gpu_session.h @@ -81,10 +81,6 @@ class GPUSession : public SessionBasic { void PostIterationDbg(const std::shared_ptr &kernel_graph) const; - void SyncValueNodeDeviceAddr(const std::shared_ptr &kernel_graph) const; - - void CleanValueNodeDeviceAddr(const std::shared_ptr &kernel_graph) const; - GraphId CompileGraphImpl(KernelGraphPtr kernel_graph); }; using GPUSessionPtr = std::shared_ptr; diff --git a/mindspore/ccsrc/backend/session/session_basic.cc b/mindspore/ccsrc/backend/session/session_basic.cc index 17c91f61a3c..c30f3220a9b 100644 --- a/mindspore/ccsrc/backend/session/session_basic.cc +++ b/mindspore/ccsrc/backend/session/session_basic.cc @@ -384,7 +384,7 @@ bool ExistSummaryNode(const KernelGraph *graph) { return false; } -void GetParameterIndex(KernelGraph *graph, const std::vector &inputs, +void GetParameterIndex(const KernelGraph *graph, const std::vector &inputs, std::map *parameter_index) { size_t index = 0; for (const auto &input_node : graph->inputs()) { @@ -492,7 +492,7 @@ void CreateOutputPlaceholder(const KernelGraphPtr &kernel_graph, const std::vect } } -void GetRefCount(KernelGraph *graph, std::map *ref_count) { +void GetRefCount(const KernelGraph *graph, std::map *ref_count) { MS_EXCEPTION_IF_NULL(graph); for (const auto &kernel : graph->execution_order()) { for (size_t i = 1; i < kernel->inputs().size(); i += 1) { diff --git a/mindspore/ccsrc/runtime/device/kernel_runtime.cc b/mindspore/ccsrc/runtime/device/kernel_runtime.cc index e3d9ab10469..add0d7426d7 100644 --- a/mindspore/ccsrc/runtime/device/kernel_runtime.cc +++ b/mindspore/ccsrc/runtime/device/kernel_runtime.cc @@ -705,52 +705,6 @@ void KernelRuntime::AssignStaticMemoryValueNode(session::KernelGraph *graph) { MS_LOG(INFO) << "AssignStaticMemoryValueNode end"; } -void KernelRuntime::SyncValueNodeDeviceAddr(session::KernelGraph *graph) { - MS_EXCEPTION_IF_NULL(graph); - MS_LOG(INFO) << "SyncValueNodeDeviceAddr start"; - for (auto &value_node : graph->graph_value_nodes()) { - MS_EXCEPTION_IF_NULL(value_node); - auto &node_value = value_node->value(); - MS_EXCEPTION_IF_NULL(node_value); - if (!node_value->isa() && !node_value->isa()) { - continue; - } - std::vector tensors; - TensorValueToTensor(node_value, &tensors); - for (size_t index = 0; index < tensors.size(); index += 1) { - const auto &tensor = tensors[index]; - if (tensor->device_address() != nullptr) { - AnfAlgo::SetOutputAddr(std::dynamic_pointer_cast(tensor->device_address()), index, - value_node.get()); - } else { - MS_LOG(INFO) << "Tensor of ValueNode[" << value_node->fullname_with_scope() << "]'s device address is nullptr."; - } - } - } - MS_LOG(INFO) << "SyncValueNodeDeviceAddr end"; -} - -void KernelRuntime::CleanValueNodeDeviceAddr(session::KernelGraph *graph) { - MS_EXCEPTION_IF_NULL(graph); - MS_LOG(INFO) << "CleanValueNodeDeviceAddr start"; - for (auto &value_node : graph->graph_value_nodes()) { - MS_EXCEPTION_IF_NULL(value_node); - auto &node_value = value_node->value(); - MS_EXCEPTION_IF_NULL(node_value); - if (!node_value->isa() && !node_value->isa()) { - continue; - } - std::vector tensors; - TensorValueToTensor(node_value, &tensors); - for (size_t index = 0; index < tensors.size(); index += 1) { - if (tensors[index]->device_address() != nullptr) { - AnfAlgo::SetOutputAddr(nullptr, index, value_node.get()); - } - } - } - MS_LOG(INFO) << "CleanValueNodeDeviceAddr end"; -} - void KernelRuntime::AssignDynamicMemory(session::KernelGraph *graph) { MS_EXCEPTION_IF_NULL(graph); MS_EXCEPTION_IF_NULL(mem_manager_); diff --git a/mindspore/ccsrc/runtime/device/kernel_runtime.h b/mindspore/ccsrc/runtime/device/kernel_runtime.h index d5c17b36cb4..fb7e1eedb29 100644 --- a/mindspore/ccsrc/runtime/device/kernel_runtime.h +++ b/mindspore/ccsrc/runtime/device/kernel_runtime.h @@ -68,8 +68,6 @@ class KernelRuntime { const AddressPtrList &kernel_workspaces) const; virtual void AssignStaticMemoryInput(const session::KernelGraph *graph); virtual void AssignStaticMemoryValueNode(session::KernelGraph *graph); - virtual void SyncValueNodeDeviceAddr(session::KernelGraph *graph); - virtual void CleanValueNodeDeviceAddr(session::KernelGraph *graph); virtual void ClearGraphRuntimeResource(uint32_t graph_id, const std::vector &inputs, const std::unordered_set &value_nodes, const std::vector &execution_order);