blob: b429a1806932322da3a7343521267a715f30c8c5 [file] [log] [blame]
Georgios Pinitas12be7ab2018-07-03 12:06:23 +01001/*
2 * Copyright (c) 2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_EXAMPLES_UTILS_COMMON_GRAPH_OPTIONS
25#define ARM_COMPUTE_EXAMPLES_UTILS_COMMON_GRAPH_OPTIONS
26
27#include "utils/command_line/CommandLineOptions.h"
28#include "utils/command_line/CommandLineParser.h"
29
30#include "arm_compute/graph/TypeLoader.h"
31#include "arm_compute/graph/TypePrinter.h"
32
33namespace arm_compute
34{
35namespace utils
36{
37/** Structure holding all the common graph parameters */
38struct CommonGraphParams
39{
40 bool help{ false };
41 int threads{ 0 };
42 arm_compute::graph::Target target{ arm_compute::graph::Target::NEON };
43 arm_compute::DataType data_type{ DataType::F32 };
44 arm_compute::DataLayout data_layout{ DataLayout::NCHW };
45 bool enable_tuner{ false };
46 arm_compute::graph::FastMathHint fast_math_hint{ arm_compute::graph::FastMathHint::DISABLED };
47 std::string data_path{};
48 std::string image{};
49 std::string labels{};
50 std::string validation_file{};
51 std::string validation_path{};
52 unsigned int validation_range_start{ 0 };
53 unsigned int validation_range_end{ std::numeric_limits<unsigned int>::max() };
54};
55
56/** Formatted output of the CommonGraphParams type
57 *
58 * @param[out] os Output stream.
59 * @param[in] common_params Common parameters to output
60 *
61 * @return Modified output stream.
62 */
63::std::ostream &operator<<(::std::ostream &os, const CommonGraphParams &common_params);
64
65/** Common command line options used to configure the graph examples
66 *
67 * The options in this object get populated when "parse()" is called on the parser used to construct it.
68 * The expected workflow is:
69 *
70 * CommandLineParser parser;
71 * CommonOptions options( parser );
72 * parser.parse(argc, argv);
73 */
74class CommonGraphOptions
75{
76public:
77 /** Constructor
78 *
79 * @param[in,out] parser A parser on which "parse()" hasn't been called yet.
80 */
81 CommonGraphOptions(CommandLineParser &parser);
Gian Marco Iodice11a7e322018-07-05 15:42:02 +010082 /** Prevent instances of this class from being copied (As this class contains pointers) */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010083 CommonGraphOptions(const CommonGraphOptions &) = delete;
Gian Marco Iodice11a7e322018-07-05 15:42:02 +010084 /** Prevent instances of this class from being copied (As this class contains pointers) */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010085 CommonGraphOptions &operator=(const CommonGraphOptions &) = delete;
Gian Marco Iodice11a7e322018-07-05 15:42:02 +010086 /** Allow instances of this class to be moved */
87 CommonGraphOptions(CommonGraphOptions &&) = default;
88 /** Allow instances of this class to be moved */
89 CommonGraphOptions &operator=(CommonGraphOptions &&) = default;
90 /** Default destructor */
91 ~CommonGraphOptions() = default;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010092
93 ToggleOption *help; /**< Show help option */
94 SimpleOption<int> *threads; /**< Number of threads option */
95 EnumOption<arm_compute::graph::Target> *target; /**< Graph execution target */
96 EnumOption<arm_compute::DataType> *data_type; /**< Graph data type */
97 EnumOption<arm_compute::DataLayout> *data_layout; /**< Graph data layout */
98 ToggleOption *enable_tuner; /**< Enable tuner */
99 ToggleOption *fast_math_hint; /**< Fast math hint */
100 SimpleOption<std::string> *data_path; /**< Trainable parameters path */
101 SimpleOption<std::string> *image; /**< Image */
102 SimpleOption<std::string> *labels; /**< Labels */
103 SimpleOption<std::string> *validation_file; /**< Validation file */
104 SimpleOption<std::string> *validation_path; /**< Validation data path */
105 SimpleOption<std::string> *validation_range; /**< Validation range */
106};
107
108/** Consumes the common graph options and creates a structure containing any information
109 *
110 * @param[in] options Options to consume
111 *
112 * @return Structure containing the commnon graph parameters
113 */
114CommonGraphParams consume_common_graph_parameters(CommonGraphOptions &options);
115} // namespace utils
116} // namespace arm_compute
117#endif /* ARM_COMPUTE_EXAMPLES_UTILS_COMMON_GRAPH_OPTIONS */