blob: 68ffe423235a2ec4965a3c21b4568f695197b45f [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Richard Burtonf32a86a2022-11-15 11:46:11 +00002 * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
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.
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010034 * @param[in] results Vector of classification results to be displayed.
35 * @return true if successful, false otherwise.
36 **/
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010037bool PresentInferenceResult(const std::vector<arm::app::ClassificationResult>& results);
Isabella Gottardi3107aa22022-01-27 16:39:37 +000038
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010039
40/**
41 * @brief Helper function to increment current input feature vector index.
42 * @param[in,out] ctx Pointer to the application context object.
43 * @param[in] useCase Use case name
44 **/
alexander31ae9f02022-02-10 16:15:54 +000045void IncrementAppCtxIfmIdx(arm::app::ApplicationContext& ctx, const std::string& useCase);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010046
47/**
48 * @brief Helper function to set the input feature map index.
49 * @param[in,out] ctx Pointer to the application context object.
50 * @param[in] idx Value to be set.
51 * @param[in] ctxIfmName Input Feature Map name
52 * @return true if index is set, false otherwise.
53 **/
alexander31ae9f02022-02-10 16:15:54 +000054bool SetAppCtxIfmIdx(arm::app::ApplicationContext& ctx, uint32_t idx, const std::string& ctxIfmName);
Éanna Ó Catháin8f958872021-09-15 09:32:30 +010055
56
57namespace common {
58
59 enum OPCODES {
60 MENU_OPT_RUN_INF_NEXT = 1, /* Run on next vector. */
61 MENU_OPT_RUN_INF_CHOSEN, /* Run on a user provided vector index. */
62 MENU_OPT_RUN_INF_ALL, /* Run inference on all. */
63 MENU_OPT_SHOW_MODEL_INFO, /* Show model info. */
64 MENU_OPT_LIST_IFM /* List the current IFM. */
65 };
66
67}
68
alexander3c798932021-03-26 21:42:19 +000069namespace arm {
70namespace app {
alexander3c798932021-03-26 21:42:19 +000071 /**
72 * @brief Run inference using given model
73 * object. If profiling is enabled, it will log the
74 * statistics too.
alexander3c798932021-03-26 21:42:19 +000075 * @param[in] model Reference to the initialised model.
Isabella Gottardi8df12f32021-04-07 17:15:31 +010076 * @param[in] profiler Reference to the initialised profiler.
alexander3c798932021-03-26 21:42:19 +000077 * @return true if inference succeeds, false otherwise.
78 **/
Isabella Gottardi56ee6202021-05-12 08:27:15 +010079 bool RunInference(arm::app::Model& model, Profiler& profiler);
alexander3c798932021-03-26 21:42:19 +000080
81 /**
82 * @brief Read input and return as an integer.
alexander3c798932021-03-26 21:42:19 +000083 * @return Integer value corresponding to the user input.
84 **/
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010085 int ReadUserInputAsInt();
alexander3c798932021-03-26 21:42:19 +000086
87#if VERIFY_TEST_OUTPUT
88 /**
89 * @brief Helper function to dump a tensor to stdout
90 * @param[in] tensor tensor to be dumped
91 * @param[in] lineBreakForNumElements number of elements
92 * after which line break will be added.
93 **/
alexander80eecfb2021-07-06 19:47:59 +010094 void DumpTensor(const TfLiteTensor* tensor,
95 size_t lineBreakForNumElements = 16);
96
97
98 void DumpTensorData(const uint8_t* tensorData,
99 size_t size,
100 size_t lineBreakForNumElements = 16);
alexander3c798932021-03-26 21:42:19 +0000101#endif /* VERIFY_TEST_OUTPUT */
102
103 /**
104 * @brief List the files baked in the application.
105 * @param[in] ctx Reference to the application context.
106 * @return true or false based on event being handled.
107 **/
108 bool ListFilesHandler(ApplicationContext& ctx);
109
110} /* namespace app */
111} /* namespace arm */
112
Éanna Ó Catháin8f958872021-09-15 09:32:30 +0100113
114#endif /* USECASE_COMMON_UTILS_HPP */