diff --git a/mindspore/lite/src/lite_kernel.cc b/mindspore/lite/src/lite_kernel.cc index b3104fc505d..6d7f5aad044 100644 --- a/mindspore/lite/src/lite_kernel.cc +++ b/mindspore/lite/src/lite_kernel.cc @@ -221,42 +221,61 @@ void LiteKernel::FindInoutKernels(const std::vector &scope std::vector LiteKernelUtil::SubgraphInputKernels( const std::vector &kernels) { - std::vector input_kernels; + std::set input_kernels; for (const auto &kernel : kernels) { + // 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()) { - input_kernels.emplace_back(kernel); + input_kernels.insert(kernel); continue; } - for (const auto &input : kernel->in_kernels()) { - auto in_kernel_in_graph = std::find(kernels.begin(), kernels.end(), input); - auto in_kernel_in_ret = std::find(input_kernels.begin(), input_kernels.end(), kernel); - if (in_kernel_in_graph == kernels.end() && in_kernel_in_ret == input_kernels.end()) { - input_kernels.emplace_back(kernel); - break; + auto all_input_tensors = kernel->in_tensors(); + // remove all const tensor from input tensors + for (auto iter = all_input_tensors.begin(); iter != all_input_tensors.end();) { + if ((*iter)->IsConst()) { + iter = all_input_tensors.erase(iter); + } else { + iter++; } } + for (const auto &kernel_in_subgraph : kernels) { + // remove input tensors from kernel in subgraph + for (const auto *tensor : kernel_in_subgraph->out_tensors()) { + auto ret = std::find(all_input_tensors.begin(), all_input_tensors.end(), tensor); + if (ret != all_input_tensors.end()) { + all_input_tensors.erase(ret); + } + } + } + // if some input tensor is not from kernel in subgraph + if (!all_input_tensors.empty()) { + input_kernels.insert(kernel); + } } - return input_kernels; + std::vector result; + result.insert(result.end(), input_kernels.begin(), input_kernels.end()); + return result; } std::vector LiteKernelUtil::SubgraphOutputKernels( const std::vector &kernels) { - std::vector output_kernels; + std::set output_kernels; + // if kernel has no post-kernel, kernel is a graph output, it must be a subgraph output for (const auto &kernel : kernels) { - if (kernel->out_kernels().empty() && !kernel->out_tensors().empty()) { - output_kernels.emplace_back(kernel); + if (kernel->is_model_output() || (kernel->out_kernels().empty() && !kernel->out_tensors().empty())) { + output_kernels.insert(kernel); continue; } for (const auto &output : kernel->out_kernels()) { auto out_kernel_in_graph = std::find(kernels.begin(), kernels.end(), output); - auto out_kernel_in_ret = std::find(output_kernels.begin(), output_kernels.end(), kernel); - if (out_kernel_in_graph == kernels.end() && out_kernel_in_ret == output_kernels.end()) { - output_kernels.emplace_back(kernel); + if (out_kernel_in_graph == kernels.end()) { + output_kernels.insert(kernel); break; } } } - return output_kernels; + std::vector result; + result.insert(result.end(), output_kernels.begin(), output_kernels.end()); + return result; } std::vector LiteKernelUtil::SubgraphInputTensors(const std::vector &kernels) { diff --git a/mindspore/lite/src/sub_graph_kernel.cc b/mindspore/lite/src/sub_graph_kernel.cc index d3888ef2bd7..76c77c0429e 100644 --- a/mindspore/lite/src/sub_graph_kernel.cc +++ b/mindspore/lite/src/sub_graph_kernel.cc @@ -166,6 +166,16 @@ int CpuSubGraph::Prepare() { tensor->set_allocator(this->context_->allocator.get()); } } + this->executor_ = new (std::nothrow) mindspore::lite::CpuExecutor; + if (this->executor_ == nullptr) { + MS_LOG(ERROR) << "new CpuExecutor failed"; + return RET_ERROR; + } + ret = this->executor_->Prepare(this->nodes_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare CpuExecutor failed"; + return ret; + } return RET_OK; } diff --git a/mindspore/lite/src/sub_graph_kernel.h b/mindspore/lite/src/sub_graph_kernel.h index 9f595c91512..d829c104702 100644 --- a/mindspore/lite/src/sub_graph_kernel.h +++ b/mindspore/lite/src/sub_graph_kernel.h @@ -122,7 +122,6 @@ class CpuSubGraph : public SubGraphKernel { const std::vector &nodes, const lite::InnerContext *ctx) : SubGraphKernel(inputs, outputs, in_kernels, out_kernels, nodes, ctx) { subgraph_type_ = kCpuFP32SubGraph; - this->executor_ = new (std::nothrow) mindspore::lite::CpuExecutor; } ~CpuSubGraph() override { delete this->executor_; } diff --git a/mindspore/lite/src/tensor.h b/mindspore/lite/src/tensor.h index ed6f3b46204..6a1c8a33895 100644 --- a/mindspore/lite/src/tensor.h +++ b/mindspore/lite/src/tensor.h @@ -163,7 +163,6 @@ class Tensor : public mindspore::tensor::MSTensor { Category category_; size_t ref_count_ = 0; size_t init_ref_count_ = 0; - size_t ready_count_ = 0; std::vector quant_params_; std::vector quant_clusters_; mindspore::lite::Allocator *allocator_ = nullptr; diff --git a/third_party/flatbuffers b/third_party/flatbuffers deleted file mode 160000 index 9e7e8cbe9f6..00000000000 --- a/third_party/flatbuffers +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9e7e8cbe9f675123dd41b7c62868acad39188cae diff --git a/third_party/protobuf b/third_party/protobuf deleted file mode 160000 index 09745575a92..00000000000 --- a/third_party/protobuf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 09745575a923640154bcf307fba8aedff47f240a