blob: 7f5dde6acb7b9be0a384af6ed6ba4e1c93c3e68b [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Liam Barrye9588502022-01-25 14:31:15 +00002 * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
alexander3c798932021-03-26 21:42:19 +00003 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef USECASE_COMMON_UTILS_HPP
18#define USECASE_COMMON_UTILS_HPP
19
20#include "hal.h"
21#include "Model.hpp"
22#include "AppContext.hpp"
23#include "Profiler.hpp"
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010024#include "UseCaseHandler.hpp" /* Handlers for different user options. */
25#include "Classifier.hpp" /* Classifier. */
26#include "InputFiles.hpp"
alexander3c798932021-03-26 21:42:19 +000027
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010028
29void DisplayCommonMenu();
30
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010031 /**
32 * @brief Presents inference results using the data presentation
33 * object.
34 * @param[in] platform Reference to the hal platform object.
35 * @param[in] results Vector of classification results to be displayed.
36 * @return true if successful, false otherwise.
37 **/
Richard Burtoned35a6f2022-02-14 11:55:35 +000038bool PresentInferenceResult(hal_platform& platform,
39 const std::vector<arm::app::ClassificationResult>& results);
Isabella Gottardi3107aa22022-01-27 16:39:37 +000040
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010041
42/**
43 * @brief Helper function to increment current input feature vector index.
44 * @param[in,out] ctx Pointer to the application context object.
45 * @param[in] useCase Use case name
46 **/
alexander31ae9f02022-02-10 16:15:54 +000047void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, const std::string& useCase);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010048
49/**
50 * @brief Helper function to set the input feature map index.
51 * @param[in,out] ctx Pointer to the application context object.
52 * @param[in] idx Value to be set.
53 * @param[in] ctxIfmName Input Feature Map name
54 * @return true if index is set, false otherwise.
55 **/
alexander31ae9f02022-02-10 16:15:54 +000056bool SetAppCtxIfmIdx(arm::app::ApplicationContext& ctx, uint32_t idx, const std::string& ctxIfmName);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010057
58
59namespace common {
60
61 enum OPCODES {
62 MENU_OPT_RUN_INF_NEXT = 1, /* Run on next vector. */
63 MENU_OPT_RUN_INF_CHOSEN, /* Run on a user provided vector index. */
64 MENU_OPT_RUN_INF_ALL, /* Run inference on all. */
65 MENU_OPT_SHOW_MODEL_INFO, /* Show model info. */
66 MENU_OPT_LIST_IFM /* List the current IFM. */
67 };
68
69}
70
alexander3c798932021-03-26 21:42:19 +000071namespace arm {
72namespace app {
alexander3c798932021-03-26 21:42:19 +000073 /**
74 * @brief Run inference using given model
75 * object. If profiling is enabled, it will log the
76 * statistics too.
alexander3c798932021-03-26 21:42:19 +000077 * @param[in] model Reference to the initialised model.
Isabella Gottardi8df12f32021-04-07 17:15:31 +010078 * @param[in] profiler Reference to the initialised profiler.
alexander3c798932021-03-26 21:42:19 +000079 * @return true if inference succeeds, false otherwise.
80 **/
Isabella Gottardi56ee6202021-05-12 08:27:15 +010081 bool RunInference(arm::app::Model& model, Profiler& profiler);
alexander3c798932021-03-26 21:42:19 +000082
83 /**
84 * @brief Read input and return as an integer.
85 * @param[in] platform Reference to the hal platform object.
alexander3c798932021-03-26 21:42:19 +000086 * @return Integer value corresponding to the user input.
87 **/
88 int ReadUserInputAsInt(hal_platform& platform);
89
90#if VERIFY_TEST_OUTPUT
91 /**
92 * @brief Helper function to dump a tensor to stdout
93 * @param[in] tensor tensor to be dumped
94 * @param[in] lineBreakForNumElements number of elements
95 * after which line break will be added.
96 **/
alexander80eecfb2021-07-06 19:47:59 +010097 void DumpTensor(const TfLiteTensor* tensor,
98 size_t lineBreakForNumElements = 16);
99
100
101 void DumpTensorData(const uint8_t* tensorData,
102 size_t size,
103 size_t lineBreakForNumElements = 16);
alexander3c798932021-03-26 21:42:19 +0000104#endif /* VERIFY_TEST_OUTPUT */
105
106 /**
107 * @brief List the files baked in the application.
108 * @param[in] ctx Reference to the application context.
109 * @return true or false based on event being handled.
110 **/
111 bool ListFilesHandler(ApplicationContext& ctx);
112
113} /* namespace app */
114} /* namespace arm */
115
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100116
117#endif /* USECASE_COMMON_UTILS_HPP */