parent
78ca53e468
commit
8237479e38
|
@ -21,7 +21,6 @@
|
|||
#include "src/common/utils.h"
|
||||
#include "src/runtime/infer_manager.h"
|
||||
#include "src/common/version_manager.h"
|
||||
#include "src/runtime/kernel/arm/base/merge.h"
|
||||
|
||||
namespace mindspore::kernel {
|
||||
using mindspore::lite::RET_ERROR;
|
||||
|
@ -29,9 +28,6 @@ using mindspore::lite::RET_OK;
|
|||
|
||||
bool LiteKernel::IsReady(const std::vector<lite::Tensor *> &scope_tensors) {
|
||||
MS_ASSERT(kernel_ != nullptr);
|
||||
if ((desc_.provider == kBuiltin) && (kernel_->type() == schema::PrimitiveType_Merge)) {
|
||||
return std::static_pointer_cast<MergeCPUKernel>(kernel_)->IsReady(scope_tensors);
|
||||
}
|
||||
auto &in_tensors = this->in_tensors();
|
||||
return std::all_of(in_tensors.begin(), in_tensors.end(), [&](lite::Tensor *in_tensor) {
|
||||
if (IsContain(scope_tensors, in_tensor)) {
|
||||
|
|
|
@ -193,7 +193,7 @@ int LiteModel::VersionVerify(flatbuffers::Verifier *verify) const {
|
|||
|
||||
int LiteModel::NodeVerify() const {
|
||||
auto tensor_size = this->all_tensors_.size();
|
||||
uint32_t subGraph_size = this->sub_graphs_.size();
|
||||
uint32_t subgraph_size = this->sub_graphs_.size();
|
||||
|
||||
for (auto &node : this->all_nodes_) {
|
||||
if (node == nullptr || node->primitive_ == nullptr) {
|
||||
|
@ -211,11 +211,10 @@ int LiteModel::NodeVerify() const {
|
|||
return RET_ERROR;
|
||||
}
|
||||
|
||||
if (IsWhileNode(node->primitive_)) {
|
||||
auto body_index = GetWhileBodySubgraphIndex(node->primitive_);
|
||||
auto cond_index = GetWhileCondSubgraphIndex(node->primitive_);
|
||||
if (static_cast<uint32_t>(body_index) >= subGraph_size || static_cast<uint32_t>(cond_index) >= subGraph_size) {
|
||||
MS_LOG(ERROR) << "index of subGraph is beyond subGraph_size.";
|
||||
if (IsPartialNode(node->primitive_)) {
|
||||
auto subgraph_index = GetPartialGraphIndex(node->primitive_);
|
||||
if (static_cast<uint32_t>(subgraph_index) >= subgraph_size) {
|
||||
MS_LOG(ERROR) << "subgraph index:" << subgraph_index << " is beyond subgraph_size: " << subgraph_size;
|
||||
return RET_ERROR;
|
||||
}
|
||||
}
|
||||
|
@ -267,10 +266,11 @@ bool LiteModel::ModelVerify() const {
|
|||
MS_LOG(ERROR) << "Model does not have a main graph.";
|
||||
return false;
|
||||
}
|
||||
auto main_graph = this->sub_graphs_.front();
|
||||
for (auto input_index : main_graph->input_indices_) {
|
||||
if (input_index >= this->all_tensors_.size()) {
|
||||
MS_LOG(ERROR) << "Graph indices is beyond tensor_size.";
|
||||
|
||||
auto all_tensors_size = this->all_tensors_.size();
|
||||
for (auto input_index : this->input_indices_) {
|
||||
if (input_index >= all_tensors_size) {
|
||||
MS_LOG(ERROR) << "Graph input indices is beyond tensor_size.";
|
||||
return false;
|
||||
}
|
||||
auto *tensor = this->all_tensors_.at(input_index);
|
||||
|
@ -283,6 +283,12 @@ bool LiteModel::ModelVerify() const {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (std::any_of(this->output_indices_.begin(), this->output_indices_.end(),
|
||||
[&all_tensors_size](const uint32_t &idx) { return idx >= all_tensors_size; })) {
|
||||
MS_LOG(ERROR) << "Graph output indices is beyond tensor_size.";
|
||||
return false;
|
||||
}
|
||||
return NodeVerify() == RET_OK && SubGraphVerify() == RET_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "src/runtime/kernel/arm/base/merge.h"
|
||||
#include "src/kernel_registry.h"
|
||||
#include "include/errorcode.h"
|
||||
#include "src/tensorlist.h"
|
||||
#include "src/common/utils.h"
|
||||
|
||||
using mindspore::lite::KernelRegistrar;
|
||||
using mindspore::lite::RET_ERROR;
|
||||
using mindspore::lite::RET_OK;
|
||||
using mindspore::schema::PrimitiveType_Merge;
|
||||
|
||||
namespace mindspore::kernel {
|
||||
int MergeCPUKernel::FreeInWorkTensor() const {
|
||||
size_t stride = in_tensors_.size() / 2;
|
||||
if (this->ready_part_ == LEFT_INPUT_PART) {
|
||||
for (size_t i = 0; i < stride; ++i) {
|
||||
auto in_tensor = in_tensors_[i];
|
||||
MS_ASSERT(in_tensor != nullptr);
|
||||
if (in_tensor->root_tensor() == in_tensor) {
|
||||
continue;
|
||||
}
|
||||
in_tensor->DecRefCount();
|
||||
}
|
||||
}
|
||||
if (this->ready_part_ == RIGHT_INPUT_PART) {
|
||||
for (size_t i = stride; i < in_tensors_.size(); ++i) {
|
||||
auto in_tensor = in_tensors_[i];
|
||||
MS_ASSERT(in_tensor != nullptr);
|
||||
if (in_tensor->root_tensor() == in_tensor) {
|
||||
continue;
|
||||
}
|
||||
in_tensor->DecRefCount();
|
||||
}
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
bool MergeCPUKernel::IsReady(const std::vector<lite::Tensor *> &scope_tensors) {
|
||||
auto ready_part = FindReadyPart(scope_tensors);
|
||||
return ready_part == LEFT_INPUT_PART || ready_part == RIGHT_INPUT_PART;
|
||||
}
|
||||
|
||||
int MergeCPUKernel::Init() {
|
||||
MS_ASSERT(in_tensors_.size() == 2 * out_tensors_.size());
|
||||
size_t stride = in_tensors_.size() / 2;
|
||||
for (size_t i = 0; i < in_tensors_.size() / 2; i++) {
|
||||
MS_ASSERT(in_tensors_[i] != nullptr);
|
||||
MS_ASSERT(in_tensors_[i + stride] != nullptr);
|
||||
if (in_tensors_[i] == in_tensors_[i + stride]) {
|
||||
in_tensors_[i]->set_root_tensor(in_tensors_[i]);
|
||||
in_tensors_[i + stride]->set_root_tensor(in_tensors_[i + stride]);
|
||||
}
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int MergeCPUKernel::ReSize() { return RET_OK; }
|
||||
|
||||
InputPart MergeCPUKernel::FindReadyPart(const std::vector<lite::Tensor *> &scope_tensors) {
|
||||
MS_ASSERT(in_tensors_.size() == 2 * out_tensors_.size());
|
||||
bool is_root_tensor_ready =
|
||||
std::all_of(this->in_tensors_.begin(), this->in_tensors_.end(), [&](lite::Tensor *in_tensor) {
|
||||
// if not in scope_tensors, not care
|
||||
if (!IsContain(scope_tensors, in_tensor)) {
|
||||
return true;
|
||||
}
|
||||
// if not a root_tensor, not care
|
||||
if (in_tensor->root_tensor() == nullptr || in_tensor->root_tensor() != in_tensor) {
|
||||
return true;
|
||||
}
|
||||
return in_tensor->IsReady();
|
||||
});
|
||||
// check if all root tensor is ready
|
||||
if (!is_root_tensor_ready) {
|
||||
return UNKNOWN_INPUT_PART;
|
||||
}
|
||||
// check one part of in tensors of merge is ready
|
||||
// if not in scope_tensors, not care
|
||||
// if in scope_tensors, in_tensor need to be ready
|
||||
if (std::all_of(
|
||||
this->in_tensors_.begin() + in_tensors().size() / 2, this->in_tensors_.end(),
|
||||
[&](lite::Tensor *in_tensor) { return !IsContain(scope_tensors, in_tensor) || in_tensor->IsReady(); })) {
|
||||
return RIGHT_INPUT_PART;
|
||||
}
|
||||
if (std::all_of(
|
||||
this->in_tensors_.begin(), this->in_tensors_.begin() + in_tensors().size() / 2,
|
||||
[&](lite::Tensor *in_tensor) { return !IsContain(scope_tensors, in_tensor) || in_tensor->IsReady(); })) {
|
||||
return LEFT_INPUT_PART;
|
||||
}
|
||||
return UNKNOWN_INPUT_PART;
|
||||
}
|
||||
|
||||
int MergeCPUKernel::Run() {
|
||||
MS_ASSERT(in_tensors_.size() == 2 * out_tensors_.size());
|
||||
ready_part_ = FindReadyPart(this->in_tensors_);
|
||||
if (ready_part_ == LEFT_INPUT_PART) {
|
||||
auto ret = MoveData(this->out_tensors_.begin(), this->out_tensors_.end(), this->in_tensors_.begin(),
|
||||
this->in_tensors_.end());
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "carry data error : " << ret;
|
||||
return ret;
|
||||
}
|
||||
} else if (ready_part_ == RIGHT_INPUT_PART) {
|
||||
auto ret = MoveData(this->out_tensors_.begin(), this->out_tensors_.end(),
|
||||
(this->in_tensors_.begin() + in_tensors_.size() / 2), this->in_tensors_.end());
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "carry data error : " << ret;
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
MS_LOG(ERROR) << "none input part of merge is ready";
|
||||
return RET_ERROR;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Merge, LiteKernelCreator<MergeCPUKernel>)
|
||||
REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Merge, LiteKernelCreator<MergeCPUKernel>)
|
||||
REG_KERNEL(kCPU, kNumberTypeBool, PrimitiveType_Merge, LiteKernelCreator<MergeCPUKernel>)
|
||||
REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Merge, LiteKernelCreator<MergeCPUKernel>)
|
||||
} // namespace mindspore::kernel
|
|
@ -1,47 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_MERGE_H_
|
||||
#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_MERGE_H_
|
||||
|
||||
#include <vector>
|
||||
#include "src/runtime/kernel/arm/base/carry_data.h"
|
||||
#include "src/tensor.h"
|
||||
#include "src/tensorlist.h"
|
||||
|
||||
namespace mindspore::kernel {
|
||||
enum InputPart { UNKNOWN_INPUT_PART, LEFT_INPUT_PART, RIGHT_INPUT_PART };
|
||||
|
||||
class MergeCPUKernel : public CarryDataKernel {
|
||||
public:
|
||||
MergeCPUKernel(OpParameter *parameter, const std::vector<lite::Tensor *> &inputs,
|
||||
const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx)
|
||||
: CarryDataKernel(parameter, inputs, outputs, ctx) {}
|
||||
bool IsReady(const std::vector<lite::Tensor *> &scope_tensors);
|
||||
~MergeCPUKernel() override = default;
|
||||
int FreeInWorkTensor() const override;
|
||||
int Init() override;
|
||||
int ReSize() override;
|
||||
int Run() override;
|
||||
|
||||
private:
|
||||
InputPart FindReadyPart(const std::vector<lite::Tensor *> &scope_tensors);
|
||||
|
||||
private:
|
||||
InputPart ready_part_ = UNKNOWN_INPUT_PART;
|
||||
};
|
||||
} // namespace mindspore::kernel
|
||||
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_MERGE_H_
|
|
@ -25,70 +25,9 @@ using mindspore::lite::RET_OK;
|
|||
using mindspore::schema::PrimitiveType_Switch;
|
||||
|
||||
namespace mindspore::kernel {
|
||||
int SwitchCPUKernel::PostProcess() {
|
||||
auto bool_tensor = in_tensors_.front();
|
||||
MS_ASSERT(bool_tensor != nullptr);
|
||||
MS_ASSERT(bool_tensor->data_type() == kNumberTypeBool);
|
||||
MS_ASSERT(bool_tensor->Size() == 1);
|
||||
auto active = static_cast<bool *>(bool_tensor->data_c());
|
||||
if (active == nullptr) {
|
||||
MS_LOG(ERROR) << "data of bool tensor is nullptr";
|
||||
return lite::RET_NULL_PTR;
|
||||
}
|
||||
size_t in_index = 1;
|
||||
size_t out_index = (*active) ? 0 : (out_tensors_.size() / 2);
|
||||
while (in_index < in_tensors_.size()) {
|
||||
in_index++;
|
||||
auto out_tensor = out_tensors_.at(out_index++);
|
||||
out_tensor->ResetRefCount();
|
||||
}
|
||||
if (!*active) {
|
||||
for (auto &in_tensor : this->in_tensors_) {
|
||||
MS_ASSERT(in_tensor != nullptr);
|
||||
auto root_tensor = in_tensor->root_tensor();
|
||||
if (root_tensor == nullptr) {
|
||||
continue;
|
||||
}
|
||||
root_tensor->DecRefCount();
|
||||
}
|
||||
}
|
||||
return FreeInWorkTensor();
|
||||
}
|
||||
|
||||
int SwitchCPUKernel::Init() { return RET_OK; }
|
||||
|
||||
int SwitchCPUKernel::ReSize() { return RET_OK; }
|
||||
|
||||
// inputs: bool*1 data*n
|
||||
// output: true-data*n, false-data*n
|
||||
int SwitchCPUKernel::Run() {
|
||||
MS_ASSERT(in_tensors_.size() >= 2);
|
||||
auto bool_tensor = in_tensors_.front();
|
||||
MS_ASSERT(bool_tensor != nullptr);
|
||||
MS_ASSERT(bool_tensor->data_type() == kNumberTypeBool);
|
||||
MS_ASSERT(bool_tensor->Size() == 1);
|
||||
auto active = static_cast<bool *>(bool_tensor->data_c());
|
||||
if (active == nullptr) {
|
||||
MS_LOG(ERROR) << "data of bool tensor is nullptr";
|
||||
return lite::RET_NULL_PTR;
|
||||
}
|
||||
if (*active) {
|
||||
auto ret = MoveData(this->out_tensors_.begin(), this->out_tensors_.begin() + out_tensors_.size() / 2,
|
||||
this->in_tensors_.begin() + 1, this->in_tensors_.end());
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "carry data error : " << ret;
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
auto ret = MoveData(this->out_tensors_.begin() + out_tensors_.size() / 2, this->out_tensors_.end(),
|
||||
this->in_tensors_.begin() + 1, this->in_tensors_.end());
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "carry data error : " << ret;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
int SwitchCPUKernel::Run() { return RET_OK; }
|
||||
|
||||
REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Switch, LiteKernelCreator<SwitchCPUKernel>)
|
||||
REG_KERNEL(kCPU, kNumberTypeFloat16, PrimitiveType_Switch, LiteKernelCreator<SwitchCPUKernel>)
|
||||
|
|
|
@ -28,7 +28,6 @@ class SwitchCPUKernel : public CarryDataKernel {
|
|||
const std::vector<lite::Tensor *> &outputs, const lite::InnerContext *ctx)
|
||||
: CarryDataKernel(parameter, inputs, outputs, ctx) {}
|
||||
~SwitchCPUKernel() override = default;
|
||||
int PostProcess() override;
|
||||
int Init() override;
|
||||
int ReSize() override;
|
||||
int Run() override;
|
||||
|
|
|
@ -21,7 +21,7 @@ mtk_transformer_decoder_joint.tflite
|
|||
quant_aware_bank_card_detection_inception.onnx
|
||||
quant_aware_bank_card_recognition_fcny.onnx
|
||||
quant_aware_identify_card_detect.onnx
|
||||
#tiny-yolov3-11.onnx;2;1,416,416,3:1,2 to open
|
||||
tiny-yolov3-11.onnx;2;1,416,416,3:1,2
|
||||
# cur acc for ml_video_edit_art_transfer is 2+%
|
||||
ml_video_edit_art_transfer.onnx;3
|
||||
#ml_table_detection.onnx: onnx quantized model
|
||||
|
|
|
@ -87,11 +87,11 @@ ml_video_edit_video_segment_gauss_adaptis_part2.pb;2
|
|||
#encoder_0111.pb;4;1:1,44:1:1
|
||||
encoder_201228.pb;3;1:1,22:1;;input_dependent
|
||||
ml_video_edit_oneclick_adaptis.pb;3
|
||||
#tacotron_encoder_stf.pb;5;1:1,62:1,62:1,62:1,62;;input_dependent need open
|
||||
tacotron_encoder_stf.pb;5;1:1,62:1,62:1,62:1,62;;input_dependent
|
||||
female_model_step2_int16_noiseout.pb;66
|
||||
ml_female_model_step6_noiseout.pb;66
|
||||
ml_male_model_step6_noiseout.pb;66
|
||||
#ml_tts_decoder_control_flow.pb;5 to open
|
||||
ml_tts_decoder_control_flow.pb;5
|
||||
ml_tts_decoder.pb;5
|
||||
ml_tts_encoder_control_flow.pb;4;1:1,22:1:1;;input_dependent
|
||||
ml_tts_vocoder.pb;66
|
||||
|
@ -100,4 +100,4 @@ gts_object_detect_Ics.pb;1;420,630,3;;input_dependent
|
|||
hiai_transformer_encoder.pb;15
|
||||
decoder_step_nocumsum_v5.pb;13;1:1,512:1,1429,2:1,127:1,127:1,127:1,127,320:1,80:1,512:1,512:1,512:1,512:1,512
|
||||
hiai_nlu_model_v2.pb;7;1,5:1,6:1,174:1,98:1,5:1,5:1,5
|
||||
#ml_audio_kit_encoder_v5.pb;6;1,32:1,32:1,32:1,32:1:1 to open
|
||||
ml_audio_kit_encoder_v5.pb;6;1,32:1,32:1,32:1,32:1:1
|
||||
|
|
Loading…
Reference in New Issue