!22512 [MS][LITE]fix bug of code review

Merge pull request !22512 from mengyuanli/bugfix
This commit is contained in:
i-robot 2021-08-28 07:39:47 +00:00 committed by Gitee
commit be009760cd
18 changed files with 40 additions and 40 deletions

View File

@ -21,9 +21,8 @@
namespace mindspore::lite {
int Executor::Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator,
const KernelCallBack &before, const KernelCallBack &after) {
MS_ASSERT(allocator != nullptr);
const std::vector<kernel::LiteKernel *> &kernels, const KernelCallBack &before,
const KernelCallBack &after) {
// clear ref_count
for (auto *kernel : kernels) {
for (auto *tensor : kernel->in_tensors()) {

View File

@ -35,8 +35,8 @@ class Executor {
}
virtual int Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator = nullptr,
const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr);
const std::vector<kernel::LiteKernel *> &kernels, const KernelCallBack &before = nullptr,
const KernelCallBack &after = nullptr);
virtual int Resize(const std::vector<mindspore::tensor::MSTensor *> &inputs,
const std::vector<std::vector<int>> &dims) {

View File

@ -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();
}

View File

@ -16,7 +16,6 @@
#include "src/inner_kernel.h"
#include <algorithm>
#include <set>
#include "src/tensor.h"
#include "src/common/utils.h"
#include "src/runtime/infer_manager.h"

View File

@ -126,14 +126,20 @@ class InnerKernel : public Kernel {
void set_in_tensors(const std::vector<lite::Tensor *> &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<lite::Tensor *> &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;
}

View File

@ -16,10 +16,8 @@
#include "src/lite_kernel.h"
#include <algorithm>
#include <set>
#include "src/tensor.h"
#include "src/common/utils.h"
#include "src/runtime/infer_manager.h"
#include "src/common/version_manager.h"
namespace mindspore::kernel {

View File

@ -16,7 +16,6 @@
#include "src/lite_kernel_util.h"
#include <queue>
#include <set>
#include "src/sub_graph_kernel.h"
namespace mindspore::kernel {
@ -25,6 +24,7 @@ using mindspore::lite::RET_OK;
std::vector<kernel::LiteKernel *> LiteKernelUtil::SubgraphInputNodes(const std::vector<kernel::LiteKernel *> &kernels) {
std::vector<kernel::LiteKernel *> 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<kernel::LiteKernel *> LiteKernelUtil::SubgraphOutputNodes(
std::vector<kernel::LiteKernel *> 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);

View File

@ -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;

View File

@ -147,8 +147,8 @@ void MindrtExecutor::FreeOutputTensor() {
}
int MindrtExecutor::Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator,
const KernelCallBack &before, const KernelCallBack &after) {
const std::vector<kernel::LiteKernel *> &kernels, const KernelCallBack &before,
const KernelCallBack &after) {
FreeOutputTensor();
auto ret = MindrtRun<Tensor>(input_data_, &output_data_, &before, &after);

View File

@ -36,8 +36,8 @@ class MindrtExecutor : public Executor {
const std::vector<Tensor *> &outputs, const lite::InnerContext *ctx) override;
int Run(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator = nullptr,
const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override;
const std::vector<kernel::LiteKernel *> &kernels, const KernelCallBack &before = nullptr,
const KernelCallBack &after = nullptr) override;
int Resize(const std::vector<mindspore::tensor::MSTensor *> &inputs,
const std::vector<std::vector<int>> &dims) override;

View File

@ -21,14 +21,14 @@
namespace mindspore::lite::opencl {
int OpenCLExecutor::Run(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator,
const KernelCallBack &before, const KernelCallBack &after) {
return RunOrTune(inputs, outputs, kernels, allocator, before, after, false);
const std::vector<kernel::LiteKernel *> &kernels, const KernelCallBack &before,
const KernelCallBack &after) {
return RunOrTune(inputs, outputs, kernels, before, after, false);
}
int OpenCLExecutor::RunOrTune(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator,
const KernelCallBack &before, const KernelCallBack &after, bool is_tune) {
const std::vector<kernel::LiteKernel *> &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) {

View File

@ -37,11 +37,11 @@ class OpenCLExecutor : public Executor {
}
int Run(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator = nullptr,
const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) override;
const std::vector<kernel::LiteKernel *> &kernels, const KernelCallBack &before = nullptr,
const KernelCallBack &after = nullptr) override;
int RunOrTune(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs,
const std::vector<kernel::LiteKernel *> &kernels, mindspore::Allocator *allocator = nullptr,
const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr, bool is_tune = false);
const std::vector<kernel::LiteKernel *> &kernels, const KernelCallBack &before = nullptr,
const KernelCallBack &after = nullptr, bool is_tune = false);
protected:
InnerContext *context = nullptr;

View File

@ -336,7 +336,7 @@ int OpenCLSubGraph::Prepare() {
if (all_kernels_infer_done_) {
auto opencl_exec = reinterpret_cast<lite::opencl::OpenCLExecutor *>(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;

View File

@ -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;

View File

@ -19,7 +19,6 @@
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include "securec/include/securec.h"
#include "include/errorcode.h"

View File

@ -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"

View File

@ -19,7 +19,6 @@
#include <algorithm>
#include "include/ms_tensor.h"
#include "src/common/log_adapter.h"
#include "schema/model_generated.h"
#include "src/tensor.h"
namespace mindspore::lite {

View File

@ -15,7 +15,6 @@
*/
#include <cmath>
#include <string>
#include <memory>
#include "src/weight_decoder.h"
#include "src/huffman_decode.h"