diff --git a/mindspore/lite/src/executor.cc b/mindspore/lite/src/executor.cc index 8be9f67fa43..146003c995c 100644 --- a/mindspore/lite/src/executor.cc +++ b/mindspore/lite/src/executor.cc @@ -21,9 +21,8 @@ namespace mindspore::lite { int Executor::Run(const std::vector &in_tensors, const std::vector &out_tensors, - const std::vector &kernels, mindspore::Allocator *allocator, - const KernelCallBack &before, const KernelCallBack &after) { - MS_ASSERT(allocator != nullptr); + const std::vector &kernels, const KernelCallBack &before, + const KernelCallBack &after) { // clear ref_count for (auto *kernel : kernels) { for (auto *tensor : kernel->in_tensors()) { diff --git a/mindspore/lite/src/executor.h b/mindspore/lite/src/executor.h index 6f2a1a92f87..522886054f7 100644 --- a/mindspore/lite/src/executor.h +++ b/mindspore/lite/src/executor.h @@ -35,8 +35,8 @@ class Executor { } virtual int Run(const std::vector &in_tensors, const std::vector &out_tensors, - const std::vector &kernels, mindspore::Allocator *allocator = nullptr, - const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); + const std::vector &kernels, const KernelCallBack &before = nullptr, + const KernelCallBack &after = nullptr); virtual int Resize(const std::vector &inputs, const std::vector> &dims) { diff --git a/mindspore/lite/src/inner_context.cc b/mindspore/lite/src/inner_context.cc index dd3df185c0d..9887f30d3e4 100644 --- a/mindspore/lite/src/inner_context.cc +++ b/mindspore/lite/src/inner_context.cc @@ -42,11 +42,13 @@ void InnerContext::InitDeviceFp16() { } InnerContext::InnerContext(const Context *context) { - this->allocator = context->allocator; - this->thread_num_ = context->thread_num_; - this->enable_parallel_ = context->enable_parallel_; - this->affinity_core_list_ = context->affinity_core_list_; - SetContextDevice(context); + if (context != nullptr) { + this->allocator = context->allocator; + this->thread_num_ = context->thread_num_; + this->enable_parallel_ = context->enable_parallel_; + this->affinity_core_list_ = context->affinity_core_list_; + SetContextDevice(context); + } InitDeviceFp16(); } diff --git a/mindspore/lite/src/inner_kernel.cc b/mindspore/lite/src/inner_kernel.cc index 7d590d66385..e15625c9451 100644 --- a/mindspore/lite/src/inner_kernel.cc +++ b/mindspore/lite/src/inner_kernel.cc @@ -16,7 +16,6 @@ #include "src/inner_kernel.h" #include -#include #include "src/tensor.h" #include "src/common/utils.h" #include "src/runtime/infer_manager.h" diff --git a/mindspore/lite/src/inner_kernel.h b/mindspore/lite/src/inner_kernel.h index 08a6b94ecb1..4584e9c7fea 100644 --- a/mindspore/lite/src/inner_kernel.h +++ b/mindspore/lite/src/inner_kernel.h @@ -126,14 +126,20 @@ class InnerKernel : public Kernel { void set_in_tensors(const std::vector &in_tensors) { this->in_tensors_ = in_tensors; } virtual void set_in_tensor(lite::Tensor *in_tensor, size_t index) { - MS_ASSERT(index < in_tensors_.size()); + if (index >= in_tensors_.size()) { + MS_LOG(ERROR) << "index: " << index << " larger than in_tensors size: " << in_tensors_.size(); + return; + } this->in_tensors_[index] = in_tensor; } void set_out_tensors(const std::vector &out_tensors) { this->out_tensors_ = out_tensors; } virtual void set_out_tensor(lite::Tensor *out_tensor, size_t index) { - MS_ASSERT(index < out_tensors_.size()); + if (index >= out_tensors_.size()) { + MS_LOG(ERROR) << "index: " << index << " larger than out_tensors size: " << out_tensors_.size(); + return; + } this->out_tensors_[index] = out_tensor; } diff --git a/mindspore/lite/src/lite_kernel.cc b/mindspore/lite/src/lite_kernel.cc index db1ad97e1d0..63c26601028 100644 --- a/mindspore/lite/src/lite_kernel.cc +++ b/mindspore/lite/src/lite_kernel.cc @@ -16,10 +16,8 @@ #include "src/lite_kernel.h" #include -#include #include "src/tensor.h" #include "src/common/utils.h" -#include "src/runtime/infer_manager.h" #include "src/common/version_manager.h" namespace mindspore::kernel { diff --git a/mindspore/lite/src/lite_kernel_util.cc b/mindspore/lite/src/lite_kernel_util.cc index e468468e001..f39ddf80623 100644 --- a/mindspore/lite/src/lite_kernel_util.cc +++ b/mindspore/lite/src/lite_kernel_util.cc @@ -16,7 +16,6 @@ #include "src/lite_kernel_util.h" #include -#include #include "src/sub_graph_kernel.h" namespace mindspore::kernel { @@ -25,6 +24,7 @@ using mindspore::lite::RET_OK; std::vector LiteKernelUtil::SubgraphInputNodes(const std::vector &kernels) { std::vector input_nodes; for (const auto &kernel : kernels) { + MS_ASSERT(kernel != nullptr); // if kernel has no pre-kernel, kernel is a graph input, it must be a subgraph input if (kernel->in_kernels().empty() && !kernel->in_tensors().empty()) { if (!lite::IsContain(input_nodes, kernel)) { @@ -65,6 +65,7 @@ std::vector LiteKernelUtil::SubgraphOutputNodes( std::vector output_nodes; // if kernel has no post-kernel, kernel is a graph output, it must be a subgraph output for (const auto &kernel : kernels) { + MS_ASSERT(kernel != nullptr); if (kernel->is_model_output() || (kernel->out_kernels().empty() && !kernel->out_tensors().empty())) { if (!lite::IsContain(output_nodes, kernel)) { output_nodes.push_back(kernel); diff --git a/mindspore/lite/src/lite_session.cc b/mindspore/lite/src/lite_session.cc index 6c04f74161b..3725b991f15 100644 --- a/mindspore/lite/src/lite_session.cc +++ b/mindspore/lite/src/lite_session.cc @@ -645,9 +645,9 @@ int LiteSession::RunGraph(const KernelCallBack &before, const KernelCallBack &af } MS_ASSERT(this->context_ != nullptr); if (before == nullptr && after == nullptr) { - ret = executor_->Run(this->inputs_, this->outputs_, this->kernels_, this->context_->allocator.get()); + ret = executor_->Run(this->inputs_, this->outputs_, this->kernels_); } else { - ret = executor_->Run(this->inputs_, this->outputs_, this->kernels_, this->context_->allocator.get(), before, after); + ret = executor_->Run(this->inputs_, this->outputs_, this->kernels_, before, after); } if (ret != RET_OK) { MS_LOG(ERROR) << "RunGraph failed : " << ret; diff --git a/mindspore/lite/src/mindrt_executor.cc b/mindspore/lite/src/mindrt_executor.cc index f6841f78d1d..ba187d2cba9 100644 --- a/mindspore/lite/src/mindrt_executor.cc +++ b/mindspore/lite/src/mindrt_executor.cc @@ -147,8 +147,8 @@ void MindrtExecutor::FreeOutputTensor() { } int MindrtExecutor::Run(const std::vector &in_tensors, const std::vector &out_tensors, - const std::vector &kernels, mindspore::Allocator *allocator, - const KernelCallBack &before, const KernelCallBack &after) { + const std::vector &kernels, const KernelCallBack &before, + const KernelCallBack &after) { FreeOutputTensor(); auto ret = MindrtRun(input_data_, &output_data_, &before, &after); diff --git a/mindspore/lite/src/mindrt_executor.h b/mindspore/lite/src/mindrt_executor.h index f05863e6f67..55d5b7755cb 100644 --- a/mindspore/lite/src/mindrt_executor.h +++ b/mindspore/lite/src/mindrt_executor.h @@ -36,8 +36,8 @@ class MindrtExecutor : public Executor { const std::vector &outputs, const lite::InnerContext *ctx) override; int Run(const std::vector &in_tensors, const std::vector &out_tensors, - const std::vector &kernels, mindspore::Allocator *allocator = nullptr, - const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override; + const std::vector &kernels, const KernelCallBack &before = nullptr, + const KernelCallBack &after = nullptr) override; int Resize(const std::vector &inputs, const std::vector> &dims) override; diff --git a/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc b/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc index aabd8b7bf62..6b9143866dc 100644 --- a/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc +++ b/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc @@ -21,14 +21,14 @@ namespace mindspore::lite::opencl { int OpenCLExecutor::Run(const std::vector &inputs, const std::vector &outputs, - const std::vector &kernels, mindspore::Allocator *allocator, - const KernelCallBack &before, const KernelCallBack &after) { - return RunOrTune(inputs, outputs, kernels, allocator, before, after, false); + const std::vector &kernels, const KernelCallBack &before, + const KernelCallBack &after) { + return RunOrTune(inputs, outputs, kernels, before, after, false); } int OpenCLExecutor::RunOrTune(const std::vector &inputs, const std::vector &outputs, - const std::vector &kernels, mindspore::Allocator *allocator, - const KernelCallBack &before, const KernelCallBack &after, bool is_tune) { + const std::vector &kernels, const KernelCallBack &before, + const KernelCallBack &after, bool is_tune) { int ret{RET_OK}; auto opencl_runtime_ins = ocl_runtime.GetInstance(); if (before != nullptr && after != nullptr) { diff --git a/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h b/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h index 6120c603b9a..4563b78abec 100644 --- a/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h +++ b/mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h @@ -37,11 +37,11 @@ class OpenCLExecutor : public Executor { } int Run(const std::vector &inputs, const std::vector &outputs, - const std::vector &kernels, mindspore::Allocator *allocator = nullptr, - const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override; + const std::vector &kernels, const KernelCallBack &before = nullptr, + const KernelCallBack &after = nullptr) override; int RunOrTune(const std::vector &inputs, const std::vector &outputs, - const std::vector &kernels, mindspore::Allocator *allocator = nullptr, - const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr, bool is_tune = false); + const std::vector &kernels, const KernelCallBack &before = nullptr, + const KernelCallBack &after = nullptr, bool is_tune = false); protected: InnerContext *context = nullptr; diff --git a/mindspore/lite/src/runtime/kernel/opencl/opencl_subgraph.cc b/mindspore/lite/src/runtime/kernel/opencl/opencl_subgraph.cc index e1c52e51949..2b3323dcd06 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/opencl_subgraph.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/opencl_subgraph.cc @@ -336,7 +336,7 @@ int OpenCLSubGraph::Prepare() { if (all_kernels_infer_done_) { auto opencl_exec = reinterpret_cast(executor_); // If tuning_mode is DEFAULT, just malloc memory for reuse. - auto ret = opencl_exec->RunOrTune(in_tensors(), out_tensors(), nodes_, allocator_.get(), nullptr, nullptr, true); + auto ret = opencl_exec->RunOrTune(in_tensors(), out_tensors(), nodes_, nullptr, nullptr, true); if (ret != RET_OK) { MS_LOG(ERROR) << "Run opencl Tuning failed: " << ret; return ret; @@ -414,7 +414,7 @@ int OpenCLSubGraph::Execute() { } } - ret = executor_->Run(in_tensors(), out_tensors(), nodes_, allocator_.get()); + ret = executor_->Run(in_tensors(), out_tensors(), nodes_); if (ret != RET_OK) { MS_LOG(ERROR) << "Run opencl executor failed: " << ret; return ret; @@ -444,7 +444,7 @@ int OpenCLSubGraph::Execute(const KernelCallBack &before, const KernelCallBack & } } - ret = executor_->Run(in_tensors(), out_tensors(), nodes_, allocator_.get(), before, after); + ret = executor_->Run(in_tensors(), out_tensors(), nodes_, before, after); if (ret != RET_OK) { MS_LOG(ERROR) << "Run opencl executor failed: " << ret; return ret; diff --git a/mindspore/lite/src/sub_graph_kernel.cc b/mindspore/lite/src/sub_graph_kernel.cc index b473b3359f0..398f6f1df5a 100644 --- a/mindspore/lite/src/sub_graph_kernel.cc +++ b/mindspore/lite/src/sub_graph_kernel.cc @@ -79,8 +79,7 @@ int SubGraphKernel::Execute(const KernelCallBack &before, const KernelCallBack & MS_LOG(ERROR) << "executor is nullptr"; return RET_ERROR; } - auto ret = executor_->Run(this->in_tensors(), this->out_tensors(), this->nodes_, this->Context()->allocator.get(), - before, after); + auto ret = executor_->Run(this->in_tensors(), this->out_tensors(), this->nodes_, before, after); if (ret != RET_OK) { MS_LOG(ERROR) << "Run sub graph failed: " << ret; return ret; diff --git a/mindspore/lite/src/tensor.cc b/mindspore/lite/src/tensor.cc index a2cd6dc943c..e302d9746ef 100644 --- a/mindspore/lite/src/tensor.cc +++ b/mindspore/lite/src/tensor.cc @@ -19,7 +19,6 @@ #include #include #include -#include #include "securec/include/securec.h" #include "include/errorcode.h" diff --git a/mindspore/lite/src/tensor.h b/mindspore/lite/src/tensor.h index 6928340d070..e00a11abd1d 100644 --- a/mindspore/lite/src/tensor.h +++ b/mindspore/lite/src/tensor.h @@ -27,7 +27,6 @@ #include "include/ms_tensor.h" #include "include/api/format.h" #include "src/runtime/inner_allocator.h" - #include "src/common/log_adapter.h" #include "schema/model_generated.h" #include "src/common/utils.h" diff --git a/mindspore/lite/src/tensorlist.cc b/mindspore/lite/src/tensorlist.cc index a325890d6ca..092c3fde65e 100644 --- a/mindspore/lite/src/tensorlist.cc +++ b/mindspore/lite/src/tensorlist.cc @@ -19,7 +19,6 @@ #include #include "include/ms_tensor.h" #include "src/common/log_adapter.h" -#include "schema/model_generated.h" #include "src/tensor.h" namespace mindspore::lite { diff --git a/mindspore/lite/src/weight_decoder.cc b/mindspore/lite/src/weight_decoder.cc index 7decd5a69f3..90d32caee44 100644 --- a/mindspore/lite/src/weight_decoder.cc +++ b/mindspore/lite/src/weight_decoder.cc @@ -15,7 +15,6 @@ */ #include #include -#include #include "src/weight_decoder.h" #include "src/huffman_decode.h"