diff options
author | Cisco Cervellera <cisco.cervellera@arm.com> | 2021-09-07 11:34:43 +0100 |
---|---|---|
committer | Cisco Cervellera <cisco.cervellera@arm.com> | 2021-09-07 11:34:43 +0100 |
commit | 0210109eb6fa486fda3774e1e74f784f1a32d770 (patch) | |
tree | 6dcbf01ee938d74cfc77e4499e4b9f2176c142d1 /source/application/tensorflow-lite-micro/Model.cc | |
parent | 314948696e0dba0ffc868863868308b027824e1f (diff) | |
download | ml-embedded-evaluation-kit-0210109eb6fa486fda3774e1e74f784f1a32d770.tar.gz |
MLECO-2160: Error repor when Ethos-U is not used
Change-Id: I0dab5308bf5c3eba9b4bb2c9bf0939ac9598d2f6
Diffstat (limited to 'source/application/tensorflow-lite-micro/Model.cc')
-rw-r--r-- | source/application/tensorflow-lite-micro/Model.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/application/tensorflow-lite-micro/Model.cc b/source/application/tensorflow-lite-micro/Model.cc index 80ef3c3..acc2f0e 100644 --- a/source/application/tensorflow-lite-micro/Model.cc +++ b/source/application/tensorflow-lite-micro/Model.cc @@ -67,6 +67,16 @@ bool arm::app::Model::Init(tflite::MicroAllocator* allocator) debug("loading op resolver\n"); this->EnlistOperations(); + +#if !defined(ARM_NPU) + /* If it is not a NPU build check if the model contains a NPU operator */ + bool contains_ethosu_operator = this->ContainsEthosUOperator(); + if (contains_ethosu_operator) + { + printf_err("Ethos-U operator present in the model but this build does not include Ethos-U drivers\n"); + return false; + } +#endif /* ARM_NPU */ /* Create allocator instance, if it doesn't exist */ this->m_pAllocator = allocator; @@ -236,6 +246,30 @@ bool arm::app::Model::IsDataSigned() const return this->GetType() == kTfLiteInt8; } +bool arm::app::Model::ContainsEthosUOperator() const +{ + /* We expect there to be only one subgraph. */ + const uint32_t nOperators = tflite::NumSubgraphOperators(this->m_pModel, 0); + const tflite::SubGraph* subgraph = this->m_pModel->subgraphs()->Get(0); + const auto* opcodes = this->m_pModel->operator_codes(); + + /* check for custom operators */ + for (size_t i = 0; (i < nOperators); ++i) + { + const tflite::Operator* op = subgraph->operators()->Get(i); + const tflite::OperatorCode* opcode = opcodes->Get(op->opcode_index()); + + auto builtin_code = tflite::GetBuiltinCode(opcode); + if ((builtin_code == tflite::BuiltinOperator_CUSTOM) && + ( nullptr != opcode->custom_code()) && + ( 0 == std::string(opcode->custom_code()->c_str()).compare("ethos-u"))) + { + return true; + } + } + return false; +} + bool arm::app::Model::RunInference() { bool inference_state = false; |