Browse Source

dump unsupported ops

pull/15496/head
zhujingxuan 4 years ago
parent
commit
51105c4b71
7 changed files with 44 additions and 17 deletions
  1. +1
    -0
      mindspore/lite/micro/cmake/file_list.cmake
  2. +5
    -5
      mindspore/lite/micro/coder/coder.cc
  3. +25
    -0
      mindspore/lite/micro/coder/graph.cc
  4. +3
    -0
      mindspore/lite/micro/coder/graph.h
  5. +2
    -2
      mindspore/lite/micro/coder/opcoders/nnacl/fp32/scale_fp32_coder.h
  6. +4
    -9
      mindspore/lite/micro/coder/opcoders/op_coder_builder.cc
  7. +4
    -1
      mindspore/lite/micro/coder/session.cc

+ 1
- 0
mindspore/lite/micro/cmake/file_list.cmake View File

@@ -152,6 +152,7 @@ set(LITE_SRC
${LITE_DIR}/src/ops/populate/full_connection_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/reduce_populate.cc
${LITE_DIR}/src/ops/populate/resize_populate.cc
${LITE_DIR}/src/ops/populate/reshape_populate.cc
${LITE_DIR}/src/ops/populate/batch_norm_populate.cc


+ 5
- 5
mindspore/lite/micro/coder/coder.cc View File

@@ -56,28 +56,28 @@ class CoderFlags : public virtual FlagParser {
int Coder::Run(const std::string &model_path) {
session_ = CreateCoderSession();
if (session_ == nullptr) {
MS_LOG(ERROR) << "new session failed while running";
MS_LOG(ERROR) << "new session failed while running!";
return RET_ERROR;
}
STATUS status = session_->Init(model_path);
if (status != RET_OK) {
MS_LOG(ERROR) << "Init session failed.";
MS_LOG(ERROR) << "Init session failed!";
return RET_ERROR;
}

status = session_->Build();
if (status != RET_OK) {
MS_LOG(ERROR) << "Set Input resize shapes error";
MS_LOG(ERROR) << "Compile graph failed!";
return status;
}
status = session_->Run();
if (status != RET_OK) {
MS_LOG(ERROR) << "Generate Code Files error. " << status;
MS_LOG(ERROR) << "Generate Code Files error!" << status;
return status;
}
status = session_->GenerateCode();
if (status != RET_OK) {
MS_LOG(ERROR) << "Generate Code Files error " << status;
MS_LOG(ERROR) << "Generate Code Files error!" << status;
}
return status;
}


+ 25
- 0
mindspore/lite/micro/coder/graph.cc View File

@@ -22,8 +22,11 @@
#include <algorithm>
#include <set>
#include "coder/log.h"
#include "coder/opcoders/op_coder_register.h"
#include "coder/utils/type_cast.h"
#include "schema/inner/model_generated.h"
#include "securec/include/securec.h"
#include "src/common/prim_util.h"

namespace mindspore::lite::micro {
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::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

+ 3
- 0
mindspore/lite/micro/coder/graph.h View File

@@ -65,6 +65,8 @@ class CoderGraph {

const Model *model() const { return this->model_; }

void DumpUnSupportLayer(Target target);

private:
// graph_inputs && weight && bias is value_node
// others are parameter_node
@@ -77,6 +79,7 @@ class CoderGraph {
std::vector<uint32_t> input_indices_;

std::vector<uint32_t> output_indices_;

std::map<std::string, std::vector<Tensor *>> inputs_map_;

std::map<std::string, std::vector<Tensor *>> outputs_map_;


+ 2
- 2
mindspore/lite/micro/coder/opcoders/nnacl/fp32/scale_fp32_coder.h View File

@@ -14,8 +14,8 @@
* 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 "coder/opcoders/op_coder.h"


+ 4
- 9
mindspore/lite/micro/coder/opcoders/op_coder_builder.cc View File

@@ -30,15 +30,10 @@ std::unique_ptr<OperatorCoder> OpCoderBuilder::build() {
CoderKey coder_key(target_, data_type_, primitive_type);
CoderCreatorFunc creator_func = OpCoderFactory::GetInstance()->FindOpCoder(coder_key);
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;
}
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";
return nullptr;
} else {
@@ -46,11 +41,11 @@ std::unique_ptr<OperatorCoder> OpCoderBuilder::build() {
MS_CHECK_PTR_RET_NULL(outputs_.at(kOutputIndex));
}
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))
<< " code_target: " << target_ << " data_type: " << EnumNameDataType(data_type_);
return op_coder;
return nullptr;
}
op_coder->set_input_tensor_indices(input_indices_);
op_coder->set_output_tensor_indices(output_indices_);


+ 4
- 1
mindspore/lite/micro/coder/session.cc View File

@@ -294,7 +294,10 @@ int CoderSession::CreateOpCoders() {
.input_indices(input_indices)
.output_indices(output_indices)
.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));
builder.Reset();
}


Loading…
Cancel
Save