Browse Source

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

Merge pull request !22512 from mengyuanli/bugfix
tags/v1.5.0-rc1
i-robot Gitee 4 years ago
parent
commit
be009760cd
18 changed files with 40 additions and 40 deletions
  1. +2
    -3
      mindspore/lite/src/executor.cc
  2. +2
    -2
      mindspore/lite/src/executor.h
  3. +7
    -5
      mindspore/lite/src/inner_context.cc
  4. +0
    -1
      mindspore/lite/src/inner_kernel.cc
  5. +8
    -2
      mindspore/lite/src/inner_kernel.h
  6. +0
    -2
      mindspore/lite/src/lite_kernel.cc
  7. +2
    -1
      mindspore/lite/src/lite_kernel_util.cc
  8. +2
    -2
      mindspore/lite/src/lite_session.cc
  9. +2
    -2
      mindspore/lite/src/mindrt_executor.cc
  10. +2
    -2
      mindspore/lite/src/mindrt_executor.h
  11. +5
    -5
      mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc
  12. +4
    -4
      mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h
  13. +3
    -3
      mindspore/lite/src/runtime/kernel/opencl/opencl_subgraph.cc
  14. +1
    -2
      mindspore/lite/src/sub_graph_kernel.cc
  15. +0
    -1
      mindspore/lite/src/tensor.cc
  16. +0
    -1
      mindspore/lite/src/tensor.h
  17. +0
    -1
      mindspore/lite/src/tensorlist.cc
  18. +0
    -1
      mindspore/lite/src/weight_decoder.cc

+ 2
- 3
mindspore/lite/src/executor.cc 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()) {


+ 2
- 2
mindspore/lite/src/executor.h 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) {


+ 7
- 5
mindspore/lite/src/inner_context.cc 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();
}



+ 0
- 1
mindspore/lite/src/inner_kernel.cc 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"


+ 8
- 2
mindspore/lite/src/inner_kernel.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;
}



+ 0
- 2
mindspore/lite/src/lite_kernel.cc 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 {


+ 2
- 1
mindspore/lite/src/lite_kernel_util.cc 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);


+ 2
- 2
mindspore/lite/src/lite_session.cc 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;


+ 2
- 2
mindspore/lite/src/mindrt_executor.cc 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);


+ 2
- 2
mindspore/lite/src/mindrt_executor.h 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;


+ 5
- 5
mindspore/lite/src/runtime/gpu/opencl/opencl_executor.cc 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) {


+ 4
- 4
mindspore/lite/src/runtime/gpu/opencl/opencl_executor.h 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;


+ 3
- 3
mindspore/lite/src/runtime/kernel/opencl/opencl_subgraph.cc 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;


+ 1
- 2
mindspore/lite/src/sub_graph_kernel.cc 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;


+ 0
- 1
mindspore/lite/src/tensor.cc View File

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



+ 0
- 1
mindspore/lite/src/tensor.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"


+ 0
- 1
mindspore/lite/src/tensorlist.cc 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 {


+ 0
- 1
mindspore/lite/src/weight_decoder.cc View File

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



Loading…
Cancel
Save