MLECO-2160: Error repor when Ethos-U is not used

Change-Id: I0dab5308bf5c3eba9b4bb2c9bf0939ac9598d2f6
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 @@
     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 @@
     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;