diff --git a/mindspore/ccsrc/backend/session/session_basic.cc b/mindspore/ccsrc/backend/session/session_basic.cc index 118d5383391..ee05757e3da 100644 --- a/mindspore/ccsrc/backend/session/session_basic.cc +++ b/mindspore/ccsrc/backend/session/session_basic.cc @@ -422,7 +422,6 @@ BaseRef CreateNodeOutputPlaceholder(const AnfNodePtr &anf, const KernelGraphPtr void CheckInputTensorShape(const TensorPtr &tensor, const CNodePtr &kernel, size_t input_index) { const auto &tensor_shape = tensor->shape(); const auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel, input_index); - if (tensor_shape.size() != input_shape.size()) { MS_LOG(EXCEPTION) << "The input tensor's shape size: " << tensor_shape.size() << " is not equal to expected size: " << input_shape.size() << " for input[" << input_index @@ -1212,7 +1211,7 @@ void SessionBasic::GetParameterIndex(const KernelGraph *graph, const std::vector } void SessionBasic::CreateOutputPlaceholder( - const KernelGraphPtr &kernel_graph, const std::vector &input_tensors, VectorRef *outputs, + const KernelGraphPtr &kernel_graph, const std::vector &input_tensors, VectorRef *const outputs, std::map>> *output_indexes) { MS_EXCEPTION_IF_NULL(kernel_graph); MS_EXCEPTION_IF_NULL(outputs); @@ -1273,7 +1272,7 @@ void SessionBasic::HandleOpInputs(const std::set &input_kernel, void SessionBasic::HandleOpOutputs(const AnfNodePtr &kernel, const VectorRef &op_outputs, const std::map &ref_count, std::map *op_output_map, - GraphOutputInfo *graph_output_info) { + GraphOutputInfo *const graph_output_info) { MS_EXCEPTION_IF_NULL(kernel); MS_EXCEPTION_IF_NULL(op_output_map); MS_EXCEPTION_IF_NULL(graph_output_info); @@ -1410,7 +1409,7 @@ tensor::TensorPtr SessionBasic::GetOpInputTensorByIndex(const CNodePtr &cnode, const std::map &op_output, const std::map ¶meter_index, const std::vector &graph_inputs, - InputTensorInfo *input_tensor_info, size_t input_index) { + InputTensorInfo *const input_tensor_info, size_t input_index) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(input_tensor_info); if (input_index >= cnode->inputs().size() - 1) { diff --git a/mindspore/ccsrc/backend/session/session_basic.h b/mindspore/ccsrc/backend/session/session_basic.h index 10d3d11a962..e20cd762351 100644 --- a/mindspore/ccsrc/backend/session/session_basic.h +++ b/mindspore/ccsrc/backend/session/session_basic.h @@ -181,7 +181,7 @@ class SessionBasic : public std::enable_shared_from_this { void GetParameterIndex(const KernelGraph *graph, const std::vector &inputs, std::map *parameter_index); void CreateOutputPlaceholder(const KernelGraphPtr &kernel_graph, const std::vector &input_tensors, - VectorRef *outputs, + VectorRef *const outputs, std::map>> *output_indexes); void GetRefCount(const KernelGraph *graph, std::map *ref_count); void HandleOpInputs(const std::set &input_kernel, std::map *ref_count, @@ -189,7 +189,8 @@ class SessionBasic : public std::enable_shared_from_this { void HandleOpOutputs(const AnfNodePtr &kernel, const VectorRef &op_outputs, const std::map &ref_count, - std::map *op_output_map, GraphOutputInfo *graph_output_info); + std::map *op_output_map, + GraphOutputInfo *const graph_output_info); protected: friend class Executor; @@ -264,7 +265,7 @@ class SessionBasic : public std::enable_shared_from_this { const std::map &op_output, const std::map ¶meter_index, const std::vector &graph_inputs, - InputTensorInfo *input_tensor_info, size_t input_index); + InputTensorInfo *const input_tensor_info, size_t input_index); // create a new kernel graph and update the graph sum KernelGraphPtr NewKernelGraph(); diff --git a/mindspore/ccsrc/runtime/framework/actor/kernel_actor.cc b/mindspore/ccsrc/runtime/framework/actor/kernel_actor.cc index 87a5b3e884f..ae5a9357850 100644 --- a/mindspore/ccsrc/runtime/framework/actor/kernel_actor.cc +++ b/mindspore/ccsrc/runtime/framework/actor/kernel_actor.cc @@ -121,7 +121,7 @@ void KernelActor::RunOpControl(AID *input_control, OpContext *cont } } -void KernelActor::RunOpControlWithInputTensor(AID *input_control, OpContext *context, +void KernelActor::RunOpControlWithInputTensor(AID *const input_control, OpContext *const context, const std::vector *input_tensors) { MS_EXCEPTION_IF_NULL(context); MS_EXCEPTION_IF_NULL(input_tensors); @@ -140,11 +140,10 @@ void KernelActor::RunOpControlWithInputTensor(AID *input_control, OpContext *alloc_list, const DeviceContext *device_context) { - MS_EXCEPTION_IF_NULL(alloc_list); +void AllocateMemory(const std::vector &alloc_list, const DeviceContext *device_context) { MS_EXCEPTION_IF_NULL(device_context); - for (auto &device_tensor : *alloc_list) { + for (auto &device_tensor : alloc_list) { MS_EXCEPTION_IF_NULL(device_tensor); if ((device_tensor->GetPtr() != nullptr) || (device_tensor->GetSize() == 0)) { continue; @@ -159,10 +158,9 @@ void AllocateMemory(std::vector *alloc_list, const DeviceContext } } -void FreeMemory(std::vector *free_list, const DeviceContext *device_context) { - MS_EXCEPTION_IF_NULL(free_list); +void FreeMemory(const std::vector &free_list, const DeviceContext *device_context) { MS_EXCEPTION_IF_NULL(device_context); - for (auto &device_tensor : *free_list) { + for (auto &device_tensor : free_list) { MS_EXCEPTION_IF_NULL(device_tensor); if (device_tensor->original_ref_count() == SIZE_MAX) { continue; @@ -186,7 +184,7 @@ void KernelActor::SendMemoryAllocReq(OpContext *context) { Async(memory_manager_aid_, &MemoryManagerActor::AllocateMemory, &memory_alloc_list_, device_context_, context, GetAID()); } else { - AllocateMemory(&memory_alloc_list_, device_context_); + AllocateMemory(memory_alloc_list_, device_context_); } } @@ -194,7 +192,7 @@ void KernelActor::SendMemoryFreeReq(OpContext *context) { if (strategy_ == GraphExecutionStrategy::kPipeline) { Async(memory_manager_aid_, &MemoryManagerActor::FreeMemory, &memory_free_list_, device_context_, context); } else { - FreeMemory(&memory_free_list_, device_context_); + FreeMemory(memory_free_list_, device_context_); } } diff --git a/mindspore/ccsrc/runtime/framework/actor/kernel_actor.h b/mindspore/ccsrc/runtime/framework/actor/kernel_actor.h index fac2b67e99d..916576a69de 100644 --- a/mindspore/ccsrc/runtime/framework/actor/kernel_actor.h +++ b/mindspore/ccsrc/runtime/framework/actor/kernel_actor.h @@ -69,7 +69,7 @@ class KernelActor : public DebugAwareActor { // The kernel actor run when receive the input control. void RunOpControl(AID *input_control, OpContext *context) override; // The kernel actor run when receive the input control and input tensors, used in step mode. - void RunOpControlWithInputTensor(AID *input_control, OpContext *context, + void RunOpControlWithInputTensor(AID *const input_control, OpContext *const context, const std::vector *input_tensors); // The memory related operation interface. diff --git a/mindspore/ccsrc/runtime/framework/graph_compiler.cc b/mindspore/ccsrc/runtime/framework/graph_compiler.cc index a3b036ded1e..6c28d71c0d4 100644 --- a/mindspore/ccsrc/runtime/framework/graph_compiler.cc +++ b/mindspore/ccsrc/runtime/framework/graph_compiler.cc @@ -373,8 +373,9 @@ GraphId GraphCompiler::CompileGraphImpl(const KernelGraphPtr &graph, const Devic } GraphId GraphCompiler::CompileGraph(const session::OpRunInfo &op_run_info, const GraphInfo &graph_info, - const std::vector *tensors_mask, std::vector *input_tensors, - bool *single_op_cache_hit, const DeviceContext *device_context) { + const std::vector *tensors_mask, + std::vector *const input_tensors, bool *single_op_cache_hit, + const DeviceContext *device_context) { // Check if the graph cache exists. auto iter = run_op_graphs_.find(graph_info); if (iter != run_op_graphs_.end()) { @@ -438,7 +439,7 @@ void GraphCompiler::CreateDeviceAddress(const KernelGraphPtr &graph, const Devic } void GraphCompiler::GetParamAndOutputIndex( - const KernelGraphPtr &graph, const std::vector &inputs, VectorRef *outputs, + const KernelGraphPtr &graph, const std::vector &inputs, VectorRef *const outputs, std::map *parameter_index, std::map>> *output_indexes) { MS_EXCEPTION_IF_NULL(session_); @@ -450,7 +451,7 @@ void GraphCompiler::GetSingleOpInputTensors(const CNodePtr &kernel, const std::map &op_output, const std::map ¶meter_index, const std::vector &graph_inputs, - InputTensorInfo *input_tensor_info) { + InputTensorInfo *const input_tensor_info) { MS_EXCEPTION_IF_NULL(session_); session_->GetOpInputTensors(kernel, op_output, parameter_index, graph_inputs, input_tensor_info); } @@ -459,14 +460,14 @@ TensorPtr GraphCompiler::GetSingleOpInputTensorByIndex(const CNodePtr &kernel, const std::map &op_output, const std::map ¶meter_index, const std::vector &graph_inputs, - InputTensorInfo *input_tensor_info, size_t input_index) { + InputTensorInfo *const input_tensor_info, size_t input_index) { MS_EXCEPTION_IF_NULL(session_); return session_->GetOpInputTensorByIndex(kernel, op_output, parameter_index, graph_inputs, input_tensor_info, input_index); } void GraphCompiler::GetSingleOpRunInfoAndGraphInfo(const CNodePtr &kernel, const std::vector &input_tensors, - OpRunInfo *run_info, GraphInfo *graph_info) { + OpRunInfo *const run_info, GraphInfo *const graph_info) { MS_EXCEPTION_IF_NULL(session_); session_->GetSingleOpRunInfo(kernel, run_info); *graph_info = session_->GetSingleOpGraphInfo(kernel, input_tensors); @@ -487,7 +488,7 @@ void GraphCompiler::UpdateRefCount(const std::set &input_kernel void GraphCompiler::RecoverGraphOutput(const AnfNodePtr &kernel, const VectorRef &op_outputs, const std::map &ref_count, std::map *op_output_map, - GraphOutputInfo *graph_output_info) const { + GraphOutputInfo *const graph_output_info) const { MS_EXCEPTION_IF_NULL(session_); session_->HandleOpOutputs(kernel, op_outputs, ref_count, op_output_map, graph_output_info); } diff --git a/mindspore/ccsrc/runtime/framework/graph_compiler.h b/mindspore/ccsrc/runtime/framework/graph_compiler.h index 50cc891232a..1593579727f 100644 --- a/mindspore/ccsrc/runtime/framework/graph_compiler.h +++ b/mindspore/ccsrc/runtime/framework/graph_compiler.h @@ -50,7 +50,7 @@ class GraphCompiler { // Construct single op kernel graph and compile the kernel graph in PyNative mode. GraphId CompileGraph(const session::OpRunInfo &op_run_info, const GraphInfo &graph_info, - const std::vector *tensors_mask, std::vector *input_tensors, + const std::vector *tensors_mask, std::vector *const input_tensors, bool *single_op_cache_hit, const DeviceContext *device_context); // Get graph by graph id, if not exist return nullptr, used in Graph mode. @@ -64,24 +64,24 @@ class GraphCompiler { // Cache index for all parameter and output nodes of kernel graph, used to get parameter of single op and // recover output of original complete back propagation kernel graph. - void GetParamAndOutputIndex(const KernelGraphPtr &graph, const std::vector &inputs, VectorRef *outputs, - std::map *parameter_index, + void GetParamAndOutputIndex(const KernelGraphPtr &graph, const std::vector &inputs, + VectorRef *const outputs, std::map *parameter_index, std::map>> *output_indexes); // Get input tensors for single op compile and run, input tensors may convert from value node and parameter in graph // and prev kernel node's output. void GetSingleOpInputTensors(const CNodePtr &kernel, const std::map &op_output, const std::map ¶meter_index, - const std::vector &graph_inputs, InputTensorInfo *input_tensor_info); + const std::vector &graph_inputs, InputTensorInfo *const input_tensor_info); // Get one input tensor for single control op, such as bprop_cut. TensorPtr GetSingleOpInputTensorByIndex(const CNodePtr &kernel, const std::map &op_output, const std::map ¶meter_index, const std::vector &graph_inputs, - InputTensorInfo *input_tensor_info, size_t input_index); + InputTensorInfo *const input_tensor_info, size_t input_index); // Get OpRunInfo and GraphInfo for single op compile and run. void GetSingleOpRunInfoAndGraphInfo(const CNodePtr &kernel, const std::vector &input_tensors, - OpRunInfo *run_info, GraphInfo *graph_info); + OpRunInfo *const run_info, GraphInfo *const graph_info); // Calculate ref count of PyNative back propagation operators. void CalculateRefCount(const KernelGraphPtr &graph, std::map *ref_count) const; @@ -95,7 +95,7 @@ class GraphCompiler { void RecoverGraphOutput(const AnfNodePtr &kernel, const VectorRef &op_outputs, const std::map &ref_count, std::map *op_output_map, - GraphOutputInfo *graph_output_info) const; + GraphOutputInfo *const graph_output_info) const; // Collect output tensors of back propagation graph for allreduce operators to average gradient, // used in PyNative distributed training mode. diff --git a/mindspore/ccsrc/runtime/framework/graph_scheduler.cc b/mindspore/ccsrc/runtime/framework/graph_scheduler.cc index 3ca63ac49dd..aa6f3fe77d8 100644 --- a/mindspore/ccsrc/runtime/framework/graph_scheduler.cc +++ b/mindspore/ccsrc/runtime/framework/graph_scheduler.cc @@ -281,7 +281,7 @@ void PrepareDataForControlWeightNode( } void EraseValueNodeTensor(const std::vector *tensors_mask, const std::vector *input_tensors, - std::vector *input_tensors_without_value_node) { + std::vector *const input_tensors_without_value_node) { MS_EXCEPTION_IF_NULL(input_tensors); if (input_tensors->size() != tensors_mask->size()) { MS_LOG(EXCEPTION) << "Input tensors size " << input_tensors->size() << " should be equal to tensors mask size " @@ -324,12 +324,12 @@ void PrepareDataForHostDataSourceActor(const std::unordered_map *host_tensors, - const DeviceContext *device_context) { +void PrepareDataForInputData(const HostQueueDataSourceActor *host_data_source_actor, const AnfNodePtr &node, + const TensorPtr &tensor, const DeviceContext *device_context, + std::vector *const host_tensors) { MS_EXCEPTION_IF_NULL(tensor); // Fill the host tensors for non weighted parameters. - if (host_data_source_actor) { + if (host_data_source_actor != nullptr) { (*host_tensors)[host_data_source_actor->FetchDataNodePosition(node)] = tensor; } @@ -698,7 +698,7 @@ void GraphScheduler::PrepareRunOp(const ActorSet *actor_set, const GraphCompiler // Prepare the device data for weights. PrepareDataForWeightNode(input_node, input_node, input_tensor, device_context); } else { - PrepareDataForInputData(host_data_source_actor, input_node, input_tensor, &host_tensors, device_context); + PrepareDataForInputData(host_data_source_actor, input_node, input_tensor, device_context, &host_tensors); } } } diff --git a/mindspore/ccsrc/runtime/hardware/cpu/cpu_device_context.cc b/mindspore/ccsrc/runtime/hardware/cpu/cpu_device_context.cc index d451e4e7018..511ef13844f 100644 --- a/mindspore/ccsrc/runtime/hardware/cpu/cpu_device_context.cc +++ b/mindspore/ccsrc/runtime/hardware/cpu/cpu_device_context.cc @@ -80,7 +80,7 @@ void CPUDeviceContext::FreeMemory(DeviceAddress *const &address) const { address->ptr_ = nullptr; } -DeviceAddressPtr CPUDeviceContext::CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format, +DeviceAddressPtr CPUDeviceContext::CreateDeviceAddress(void *const device_ptr, size_t device_size, const string &format, TypeId type_id) const { return std::make_shared(device_ptr, device_size, format, type_id); } @@ -246,7 +246,7 @@ bool CPUDeviceContext::LaunchKernelWithProfiling(const CNodePtr &kernel, const s return ret; } -bool CPUDeviceContext::DoLaunchKernel(KernelMod *kernel_mod, const std::vector &inputs, +bool CPUDeviceContext::DoLaunchKernel(KernelMod *const kernel_mod, const std::vector &inputs, const std::vector &workspace, const std::vector &outputs) const { MS_EXCEPTION_IF_NULL(kernel_mod); diff --git a/mindspore/ccsrc/runtime/hardware/cpu/cpu_device_context.h b/mindspore/ccsrc/runtime/hardware/cpu/cpu_device_context.h index 187effd8b83..62a0ae5b69b 100644 --- a/mindspore/ccsrc/runtime/hardware/cpu/cpu_device_context.h +++ b/mindspore/ccsrc/runtime/hardware/cpu/cpu_device_context.h @@ -38,7 +38,7 @@ class CPUDeviceContext : public DeviceContext { bool AllocateMemory(DeviceAddress *const &address, size_t size) const override; void FreeMemory(DeviceAddress *const &address) const override; - DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format, + DeviceAddressPtr CreateDeviceAddress(void *const device_ptr, size_t device_size, const string &format, TypeId type_id) const override; DeviceAddressType GetDeviceAddressType() const override { return DeviceAddressType::kCPU; } @@ -69,11 +69,10 @@ class CPUDeviceContext : public DeviceContext { const std::vector &outputs) const; // Launch a kernel by 'KernelMod' of the kernel. - bool DoLaunchKernel(KernelMod *kernel_mod, const std::vector &inputs, + bool DoLaunchKernel(KernelMod *const kernel_mod, const std::vector &inputs, const std::vector &workspace, const std::vector &outputs) const; mutable std::mutex launch_mutex_; - uint32_t device_id_; std::shared_ptr mem_manager_; bool initialized_; }; diff --git a/mindspore/ccsrc/runtime/hardware/device_context.h b/mindspore/ccsrc/runtime/hardware/device_context.h index 3998dd80cc1..fb436178f8e 100644 --- a/mindspore/ccsrc/runtime/hardware/device_context.h +++ b/mindspore/ccsrc/runtime/hardware/device_context.h @@ -65,7 +65,7 @@ class DeviceContext { } // Create concrete device address according different device type. - virtual DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format, + virtual DeviceAddressPtr CreateDeviceAddress(void *const device_ptr, size_t device_size, const string &format, TypeId type_id) const = 0; // Get device address type according different device type, such GPU, Ascend. diff --git a/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.cc b/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.cc index 1525b5abcc5..e1b14449c5d 100644 --- a/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.cc +++ b/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.cc @@ -198,7 +198,7 @@ bool GPUDeviceContext::AllocateContinuousMemory(const std::vectorMallocContinuousMemFromMemPool(addr_list, total_size, size_list); } -DeviceAddressPtr GPUDeviceContext::CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format, +DeviceAddressPtr GPUDeviceContext::CreateDeviceAddress(void *const device_ptr, size_t device_size, const string &format, TypeId type_id) const { return std::make_shared(device_ptr, device_size, format, type_id); } @@ -361,7 +361,6 @@ void GPUDeviceContext::UpdateDynamicShape(const CNodePtr &kernel) const { MS_EXCEPTION_IF_NULL(ms_context); bool is_pynative_infer = ms_context->get_param(MS_CTX_ENABLE_PYNATIVE_INFER); bool is_pynative_mode = ms_context->get_param(MS_CTX_EXECUTION_MODE) == kPynativeMode; - if (is_pynative_infer || is_pynative_mode) { return; } diff --git a/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.h b/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.h index e63d91bd87d..2294cd355af 100644 --- a/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.h +++ b/mindspore/ccsrc/runtime/hardware/gpu/gpu_device_context.h @@ -44,7 +44,7 @@ class GPUDeviceContext : public DeviceContext { bool AllocateContinuousMemory(const std::vector &addr_list, size_t total_size, const std::vector &size_list) const override; - DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format, + DeviceAddressPtr CreateDeviceAddress(void *const device_ptr, size_t device_size, const string &format, TypeId type_id) const override; DeviceAddressType GetDeviceAddressType() const override { return DeviceAddressType::kGPU; } diff --git a/mindspore/ccsrc/vm/backend.cc b/mindspore/ccsrc/vm/backend.cc index 43dced53787..30bb60899a4 100644 --- a/mindspore/ccsrc/vm/backend.cc +++ b/mindspore/ccsrc/vm/backend.cc @@ -388,7 +388,7 @@ void MindRTBackend::CompileGraph(const FuncGraphPtr &func_graph) { MS_EXCEPTION_IF_NULL(graph_partition_); MS_EXCEPTION_IF_NULL(graph_compiler_); - bool contain_multi_target; + bool contain_multi_target = false; // Split graph to segments. const auto &segments = graph_partition_->Partition(func_graph, &contain_multi_target); MS_LOG(INFO) << "Compile graph: " << func_graph->ToString() << ", Split segments size:" << segments.size(); @@ -450,7 +450,7 @@ const ActorInfo &MindRTBackend::CompileGraph(const OpRunInfo &op_run_info, const device::DeviceContextManager::GetInstance().GetOrCreateDeviceContext({device_name_, device_id_}); device_context->Initialize(); - bool single_op_cache_hit; + bool single_op_cache_hit = true; auto graph_id = graph_compiler_->CompileGraph(op_run_info, graph_info, tensors_mask, input_tensors, &single_op_cache_hit, device_context); // The actor set name: graph_id + single operator name. @@ -592,9 +592,8 @@ void RunControlOperator(const std::shared_ptr graph_compiler, con VectorRef args; GetControlOpInput(graph_compiler, cnode, kernel, op_output_map, parameter_index, graph_inputs, input_tensor_info, &args); - BaseRef out = prim->RunHookFunction(args); - + // Convert pyobject output to tensor. if (utils::isa(out)) { PyObjectRef py_ref = utils::cast(out); auto out_py_tuple = py_ref.object_;