| @@ -152,6 +152,7 @@ set(LITE_SRC | |||||
| ${LITE_DIR}/src/ops/populate/full_connection_populate.cc | ${LITE_DIR}/src/ops/populate/full_connection_populate.cc | ||||
| ${LITE_DIR}/src/ops/populate/pooling_populate.cc | ${LITE_DIR}/src/ops/populate/pooling_populate.cc | ||||
| ${LITE_DIR}/src/ops/populate/quant_dtype_cast_populate.cc | ${LITE_DIR}/src/ops/populate/quant_dtype_cast_populate.cc | ||||
| ${LITE_DIR}/src/ops/populate/reduce_populate.cc | |||||
| ${LITE_DIR}/src/ops/populate/resize_populate.cc | ${LITE_DIR}/src/ops/populate/resize_populate.cc | ||||
| ${LITE_DIR}/src/ops/populate/reshape_populate.cc | ${LITE_DIR}/src/ops/populate/reshape_populate.cc | ||||
| ${LITE_DIR}/src/ops/populate/batch_norm_populate.cc | ${LITE_DIR}/src/ops/populate/batch_norm_populate.cc | ||||
| @@ -56,28 +56,28 @@ class CoderFlags : public virtual FlagParser { | |||||
| int Coder::Run(const std::string &model_path) { | int Coder::Run(const std::string &model_path) { | ||||
| session_ = CreateCoderSession(); | session_ = CreateCoderSession(); | ||||
| if (session_ == nullptr) { | if (session_ == nullptr) { | ||||
| MS_LOG(ERROR) << "new session failed while running"; | |||||
| MS_LOG(ERROR) << "new session failed while running!"; | |||||
| return RET_ERROR; | return RET_ERROR; | ||||
| } | } | ||||
| STATUS status = session_->Init(model_path); | STATUS status = session_->Init(model_path); | ||||
| if (status != RET_OK) { | if (status != RET_OK) { | ||||
| MS_LOG(ERROR) << "Init session failed."; | |||||
| MS_LOG(ERROR) << "Init session failed!"; | |||||
| return RET_ERROR; | return RET_ERROR; | ||||
| } | } | ||||
| status = session_->Build(); | status = session_->Build(); | ||||
| if (status != RET_OK) { | if (status != RET_OK) { | ||||
| MS_LOG(ERROR) << "Set Input resize shapes error"; | |||||
| MS_LOG(ERROR) << "Compile graph failed!"; | |||||
| return status; | return status; | ||||
| } | } | ||||
| status = session_->Run(); | status = session_->Run(); | ||||
| if (status != RET_OK) { | if (status != RET_OK) { | ||||
| MS_LOG(ERROR) << "Generate Code Files error. " << status; | |||||
| MS_LOG(ERROR) << "Generate Code Files error!" << status; | |||||
| return status; | return status; | ||||
| } | } | ||||
| status = session_->GenerateCode(); | status = session_->GenerateCode(); | ||||
| if (status != RET_OK) { | if (status != RET_OK) { | ||||
| MS_LOG(ERROR) << "Generate Code Files error " << status; | |||||
| MS_LOG(ERROR) << "Generate Code Files error!" << status; | |||||
| } | } | ||||
| return status; | return status; | ||||
| } | } | ||||
| @@ -22,8 +22,11 @@ | |||||
| #include <algorithm> | #include <algorithm> | ||||
| #include <set> | #include <set> | ||||
| #include "coder/log.h" | #include "coder/log.h" | ||||
| #include "coder/opcoders/op_coder_register.h" | |||||
| #include "coder/utils/type_cast.h" | |||||
| #include "schema/inner/model_generated.h" | #include "schema/inner/model_generated.h" | ||||
| #include "securec/include/securec.h" | #include "securec/include/securec.h" | ||||
| #include "src/common/prim_util.h" | |||||
| namespace mindspore::lite::micro { | namespace mindspore::lite::micro { | ||||
| CoderGraph::~CoderGraph() { | CoderGraph::~CoderGraph() { | ||||
| @@ -233,4 +236,26 @@ const std::map<std::string, std::vector<lite::Tensor *>> &CoderGraph::GetOutputs | |||||
| std::vector<uint32_t> CoderGraph::input_indices() const { return this->input_indices_; } | std::vector<uint32_t> CoderGraph::input_indices() const { return this->input_indices_; } | ||||
| std::vector<uint32_t> CoderGraph::output_indices() const { return this->output_indices_; } | std::vector<uint32_t> CoderGraph::output_indices() const { return this->output_indices_; } | ||||
| void CoderGraph::DumpUnSupportLayer(Target target) { | |||||
| std::cerr << "==========dump all unsupported layer for codegen=====" << std::endl; | |||||
| std::for_each(model_->all_nodes_.begin(), model_->all_nodes_.end(), [this, target](const Model::Node *node) { | |||||
| if (node->primitive_ == nullptr) { | |||||
| return; | |||||
| } | |||||
| // fake create opcoders | |||||
| uint32_t input_idx = node->input_indices_.at(0); | |||||
| Tensor *t = all_tensors_.at(input_idx); | |||||
| TypeId dtype = t->data_type(); | |||||
| int pt = GetPrimitiveType(node->primitive_); | |||||
| CoderKey key(target, dtype, pt); | |||||
| // search from the opcoder registry | |||||
| if (OpCoderFactory::GetInstance()->FindOpCoder(key) == nullptr) { | |||||
| std::cerr << node->name_ << ", primitive type: " | |||||
| << mindspore::schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(pt)) | |||||
| << ", data_type: " << EnumNameDataType(dtype) << std::endl; | |||||
| } | |||||
| }); | |||||
| } | |||||
| } // namespace mindspore::lite::micro | } // namespace mindspore::lite::micro | ||||
| @@ -65,6 +65,8 @@ class CoderGraph { | |||||
| const Model *model() const { return this->model_; } | const Model *model() const { return this->model_; } | ||||
| void DumpUnSupportLayer(Target target); | |||||
| private: | private: | ||||
| // graph_inputs && weight && bias is value_node | // graph_inputs && weight && bias is value_node | ||||
| // others are parameter_node | // others are parameter_node | ||||
| @@ -77,6 +79,7 @@ class CoderGraph { | |||||
| std::vector<uint32_t> input_indices_; | std::vector<uint32_t> input_indices_; | ||||
| std::vector<uint32_t> output_indices_; | std::vector<uint32_t> output_indices_; | ||||
| std::map<std::string, std::vector<Tensor *>> inputs_map_; | std::map<std::string, std::vector<Tensor *>> inputs_map_; | ||||
| std::map<std::string, std::vector<Tensor *>> outputs_map_; | std::map<std::string, std::vector<Tensor *>> outputs_map_; | ||||
| @@ -14,8 +14,8 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MICRO_CODER_OPCODERS_FP32_SCALEFP32_CODER_H_ | |||||
| #define MICRO_CODER_OPCODERS_FP32_SCALEFP32_CODER_H_ | |||||
| #ifndef MINDSPORE_LITE_MICRO_CODER_OPCODERS_FP32_SCALEFP32_CODER_H_ | |||||
| #define MINDSPORE_LITE_MICRO_CODER_OPCODERS_FP32_SCALEFP32_CODER_H_ | |||||
| #include <vector> | #include <vector> | ||||
| #include "coder/opcoders/op_coder.h" | #include "coder/opcoders/op_coder.h" | ||||
| @@ -30,15 +30,10 @@ std::unique_ptr<OperatorCoder> OpCoderBuilder::build() { | |||||
| CoderKey coder_key(target_, data_type_, primitive_type); | CoderKey coder_key(target_, data_type_, primitive_type); | ||||
| CoderCreatorFunc creator_func = OpCoderFactory::GetInstance()->FindOpCoder(coder_key); | CoderCreatorFunc creator_func = OpCoderFactory::GetInstance()->FindOpCoder(coder_key); | ||||
| if (creator_func == nullptr) { | if (creator_func == nullptr) { | ||||
| MS_LOG(ERROR) << "coderFactor create a null op_coder: " << node_->name_ << " primitive type: " | |||||
| << mindspore::schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(primitive_type)) | |||||
| << " code_target: " << target_ << " data_type: " << EnumNameDataType(data_type_); | |||||
| MS_LOG(ERROR) << "caught unsupported layer: " << node_->name_; | |||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| if (inputs_.empty() || outputs_.empty()) { | if (inputs_.empty() || outputs_.empty()) { | ||||
| MS_LOG(ERROR) << "coderFactor create a null op_coder: " << node_->name_ << " primitive type: " | |||||
| << mindspore::schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(primitive_type)) | |||||
| << " code_target: " << target_ << " data_type: " << EnumNameDataType(data_type_); | |||||
| MS_LOG(ERROR) << "input tensors or output tensors are empty"; | MS_LOG(ERROR) << "input tensors or output tensors are empty"; | ||||
| return nullptr; | return nullptr; | ||||
| } else { | } else { | ||||
| @@ -46,11 +41,11 @@ std::unique_ptr<OperatorCoder> OpCoderBuilder::build() { | |||||
| MS_CHECK_PTR_RET_NULL(outputs_.at(kOutputIndex)); | MS_CHECK_PTR_RET_NULL(outputs_.at(kOutputIndex)); | ||||
| } | } | ||||
| std::unique_ptr<OperatorCoder> op_coder = creator_func(inputs_, outputs_, node_, node_index_++, target_); | std::unique_ptr<OperatorCoder> op_coder = creator_func(inputs_, outputs_, node_, node_index_++, target_); | ||||
| if (!op_coder) { | |||||
| MS_LOG(ERROR) << "coderFactor create a null op_coder: " << node_->name_ << " primitive type: " | |||||
| if (op_coder == nullptr) { | |||||
| MS_LOG(ERROR) << "create op_coder failed: " << node_->name_ << " primitive type: " | |||||
| << mindspore::schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(primitive_type)) | << mindspore::schema::EnumNamePrimitiveType(static_cast<schema::PrimitiveType>(primitive_type)) | ||||
| << " code_target: " << target_ << " data_type: " << EnumNameDataType(data_type_); | << " code_target: " << target_ << " data_type: " << EnumNameDataType(data_type_); | ||||
| return op_coder; | |||||
| return nullptr; | |||||
| } | } | ||||
| op_coder->set_input_tensor_indices(input_indices_); | op_coder->set_input_tensor_indices(input_indices_); | ||||
| op_coder->set_output_tensor_indices(output_indices_); | op_coder->set_output_tensor_indices(output_indices_); | ||||
| @@ -294,7 +294,10 @@ int CoderSession::CreateOpCoders() { | |||||
| .input_indices(input_indices) | .input_indices(input_indices) | ||||
| .output_indices(output_indices) | .output_indices(output_indices) | ||||
| .build(); | .build(); | ||||
| MS_CHECK_PTR(op_coder); | |||||
| if (op_coder == nullptr) { | |||||
| coder_graph_->DumpUnSupportLayer(code_target); | |||||
| return RET_ERROR; | |||||
| } | |||||
| op_coders_.push_back(std::move(op_coder)); | op_coders_.push_back(std::move(op_coder)); | ||||
| builder.Reset(); | builder.Reset(); | ||||
| } | } | ||||