From 937052db1df7050f95e14f3ce87a36c3787a7641 Mon Sep 17 00:00:00 2001 From: Kshitij Sisodia Date: Fri, 13 May 2022 16:44:16 +0100 Subject: MLECO-3101: Minor changes for CMSIS pack Improvements based on feedback from initial tests done with the generated pack. Change-Id: Ia769dd6264c53e6b9337473e1c50bdfa6469a216 Signed-off-by: Kshitij Sisodia --- scripts/cmake/cmsis-pack-gen/CMakeLists.txt | 9 ++++++++ scripts/cmake/cmsis-pack-gen/use-case-api.yml | 7 ++++++- source/application/api/common/include/Model.hpp | 24 +++++++++++----------- .../api/common/include/TensorFlowLiteMicro.hpp | 14 ++++++------- source/application/api/common/source/Model.cc | 2 +- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/scripts/cmake/cmsis-pack-gen/CMakeLists.txt b/scripts/cmake/cmsis-pack-gen/CMakeLists.txt index 2a25aec..2774ab2 100644 --- a/scripts/cmake/cmsis-pack-gen/CMakeLists.txt +++ b/scripts/cmake/cmsis-pack-gen/CMakeLists.txt @@ -51,3 +51,12 @@ file(GLOB UC_API_LIST "${API_UC_PROJECT_DIR}/*") foreach(API ${UC_API_LIST}) add_subdirectory(${API} ${CMAKE_BINARY_DIR}/${API}) endforeach() + +# Any custom steps that are required for the CMSIS pack generation flow +# must be declared here: +if (CMSIS_PACK_GEN_FLOW) + # For CMSIS packs, we need CMSIS DSP definition. + # @TODO: Currently, this line is added multiple times to the include file. Uncomment when + # packgen is fixed. + # add_compile_definitions(arm_math PRIVATE ARM_MATH_DSP) +endif() diff --git a/scripts/cmake/cmsis-pack-gen/use-case-api.yml b/scripts/cmake/cmsis-pack-gen/use-case-api.yml index 9620e17..8796dff 100644 --- a/scripts/cmake/cmsis-pack-gen/use-case-api.yml +++ b/scripts/cmake/cmsis-pack-gen/use-case-api.yml @@ -35,7 +35,7 @@ build: - name: "build-dir" - options: "cmake" + options: "cmake -DCMSIS_PACK_GEN_FLOW=ON" packs: - name: "ml-embedded-eval-kit-uc-api" @@ -79,11 +79,16 @@ packs: target: arm_math attributes: { Cclass: "Machine Learning", Cgroup: "Evaluation Kit", Csub: "Common: Math", Cversion: "1.0.0" } description: "Math function helpers dependent on CMSIS-DSP." + conditions: + - require: { Cclass: "CMSIS", Cgroup: "DSP"} - name: common_api target: common_api attributes: {Cclass: "Machine Learning", Cgroup: "Evaluation Kit", Csub: "Common: API", Cversion: "1.0.0"} description: "Common API" + dependencies: ["arm_math", "log"] + conditions: + - require: { Cclass: "Machine Learning", Cgroup: "TensorFlow" } - name: ad_api target: ad_api diff --git a/source/application/api/common/include/Model.hpp b/source/application/api/common/include/Model.hpp index df1b259..70c6245 100644 --- a/source/application/api/common/include/Model.hpp +++ b/source/application/api/common/include/Model.hpp @@ -74,7 +74,7 @@ namespace app { **/ bool Init(uint8_t* tensorArenaAddr, uint32_t tensorArenaSize, - uint8_t* nnModelAddr, + const uint8_t* nnModelAddr, uint32_t nnModelSize, tflite::MicroAllocator* allocator = nullptr); @@ -133,17 +133,17 @@ namespace app { size_t GetActivationBufferSize(); private: - tflite::ErrorReporter* m_pErrorReporter = nullptr; /* Pointer to the error reporter. */ - const tflite::Model* m_pModel = nullptr; /* Tflite model pointer. */ - tflite::MicroInterpreter* m_pInterpreter = nullptr; /* Tflite interpreter. */ - tflite::MicroAllocator* m_pAllocator = nullptr; /* Tflite micro allocator. */ - bool m_inited = false; /* Indicates whether this object has been initialised. */ - uint8_t* m_modelAddr = nullptr; /* Model address */ - uint32_t m_modelSize = 0; /* Model size */ - - std::vector m_input = {}; /* Model's input tensor pointers. */ - std::vector m_output = {}; /* Model's output tensor pointers. */ - TfLiteType m_type = kTfLiteNoType;/* Model's data type. */ + tflite::ErrorReporter* m_pErrorReporter{nullptr}; /* Pointer to the error reporter. */ + const tflite::Model* m_pModel{nullptr}; /* Tflite model pointer. */ + tflite::MicroInterpreter* m_pInterpreter{nullptr}; /* Tflite interpreter. */ + tflite::MicroAllocator* m_pAllocator{nullptr}; /* Tflite micro allocator. */ + bool m_inited{false}; /* Indicates whether this object has been initialised. */ + const uint8_t* m_modelAddr{nullptr}; /* Model address */ + uint32_t m_modelSize{0}; /* Model size */ + + std::vector m_input{}; /* Model's input tensor pointers. */ + std::vector m_output{}; /* Model's output tensor pointers. */ + TfLiteType m_type{kTfLiteNoType}; /* Model's data type. */ }; } /* namespace app */ diff --git a/source/application/api/common/include/TensorFlowLiteMicro.hpp b/source/application/api/common/include/TensorFlowLiteMicro.hpp index f6639fd..4f9c0b3 100644 --- a/source/application/api/common/include/TensorFlowLiteMicro.hpp +++ b/source/application/api/common/include/TensorFlowLiteMicro.hpp @@ -73,13 +73,6 @@ namespace app { */ QuantParams GetTensorQuantParams(TfLiteTensor* tensor); - /** - * @brief String logging functionality expected to be defined - * by TensorFlow Lite Micro's error reporter. - * @param[in] s Pointer to the string. - */ - extern "C" void DebugLog(const char* s); - } /* namespace app */ } /* namespace arm */ @@ -88,4 +81,11 @@ namespace app { */ void PrintTensorFlowVersion(); +/** + * @brief String logging functionality expected to be defined + * by TensorFlow Lite Micro's error reporter. + * @param[in] s Pointer to the string. + */ +extern "C" void DebugLog(const char* s) __attribute__((__weak__)); + #endif /* TENSORFLOW_LITE_MICRO_LOCAL_HPP */ diff --git a/source/application/api/common/source/Model.cc b/source/application/api/common/source/Model.cc index f1ac91d..d2c7167 100644 --- a/source/application/api/common/source/Model.cc +++ b/source/application/api/common/source/Model.cc @@ -37,7 +37,7 @@ arm::app::Model::Model() : bool arm::app::Model::Init(uint8_t* tensorArenaAddr, uint32_t tensorArenaSize, - uint8_t* nnModelAddr, + const uint8_t* nnModelAddr, uint32_t nnModelSize, tflite::MicroAllocator* allocator) { -- cgit v1.2.1