blob: f8031d955c6d96c986a79a243a732a874249b0bf [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001
Jerry Gea793f462023-04-11 00:05:02 +00002// Copyright (c) 2020-2023, ARM Limited.
Eric Kunzee5e26762020-10-13 16:11:07 -07003//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
Matthew Sloyanba5fad32022-09-26 13:31:43 +010016#ifndef COMMAND_LINE_UTILS_H_
17#define COMMAND_LINE_UTILS_H_
Eric Kunzee5e26762020-10-13 16:11:07 -070018
19#include "func_config.h"
20#include "func_debug.h"
21
Matthew Sloyanba5fad32022-09-26 13:31:43 +010022#include <cxxopts.hpp>
Jerry Ge9c9c8da2023-07-19 23:08:16 +000023#include <stdint.h>
Matthew Sloyanba5fad32022-09-26 13:31:43 +010024
Eric Kunzee5e26762020-10-13 16:11:07 -070025// Read the command line arguments
Kevin Cheng10096742021-10-20 19:51:41 +000026int func_model_parse_cmd_line(
Eric Kunze286f8342022-06-22 11:30:23 -070027 func_config_t& func_config, func_debug_t& func_debug, int argc, char** argv, const char* version)
Eric Kunzee5e26762020-10-13 16:11:07 -070028{
Eric Kunze286f8342022-06-22 11:30:23 -070029 try
Eric Kunzee5e26762020-10-13 16:11:07 -070030 {
Eric Kunze286f8342022-06-22 11:30:23 -070031 cxxopts::Options options("tosa_reference_model", "The TOSA reference model");
32
33 // clang-format off
34 options.add_options()
35 ("operator_fbs", "Flat buffer schema file", cxxopts::value<std::string>(func_config.operator_fbs), "<schema>")
36 ("test_desc", "Json test descriptor", cxxopts::value<std::string>(func_config.test_desc), "<descriptor>")
37 ("flatbuffer_dir", "Flatbuffer directory to load. If not specified, it will be overwritten by dirname(test_desc)",
38 cxxopts::value<std::string>(func_config.flatbuffer_dir))
39 ("output_dir", "Output directory to write. If not specified, it will be overwritten by dirname(test_desc)",
40 cxxopts::value<std::string>(func_config.output_dir))
41 ("tosa_file", "Flatbuffer file. Support .json or .tosa. Specifying this will overwrite the one initialized by --test_desc.",
42 cxxopts::value<std::string>(func_config.tosa_file))
43 ("ifm_name", "Input tensor name. Comma(,) separated. Specifying this will overwrite the one initialized by --test_desc.",
44 cxxopts::value<std::string>(func_config.ifm_name))
45 ("ifm_file", "Input tensor numpy Comma(,) separated. file to initialize with placeholder. Specifying this will overwrite the one initialized by --test_desc.",
46 cxxopts::value<std::string>(func_config.ifm_file))
47 ("ofm_name", "Output tensor name. Comma(,) seperated. Specifying this will overwrite the one initialized by --test_desc.",
48 cxxopts::value<std::string>(func_config.ofm_name))
49 ("ofm_file", "Output tensor numpy file to be generated. Comma(,) seperated. Specifying this will overwrite the one initialized by --test_desc.",
50 cxxopts::value<std::string>(func_config.ofm_file))
Tai Ly47625642023-09-07 20:49:09 +000051 ("variable_name", "Region tensor name. Comma(,) seperated. Specifying this will overwrite the one initialized by --test_desc.",
52 cxxopts::value<std::string>(func_config.variable_name))
53 ("variable_file", "Region tensor numpy file to be generated. Comma(,) seperated. Specifying this will overwrite the one initialized by --test_desc.",
54 cxxopts::value<std::string>(func_config.variable_file))
Eric Kunze286f8342022-06-22 11:30:23 -070055 ("eval", "Evaluate the network (0/1)", cxxopts::value<uint32_t>(func_config.eval))
56 ("fp_format", "Floating-point number dump format string (printf-style format, e.g. 0.5)",
57 cxxopts::value<std::string>(func_config.fp_format))
58 ("validate_only", "Validate the network, but do not read inputs or evaluate (0/1)",
59 cxxopts::value<uint32_t>(func_config.validate_only))
60 ("output_tensors", "Output tensors to a file (0/1)", cxxopts::value<uint32_t>(func_config.output_tensors))
61 ("tosa_profile", "Set TOSA profile (0 = Base Inference, 1 = Main Inference, 2 = Main Training)",
62 cxxopts::value<uint32_t>(func_config.tosa_profile))
Jerry Gea793f462023-04-11 00:05:02 +000063 ("tosa_level", "Set TOSA level (NONE, EIGHTK)",
64 cxxopts::value<tosa_level_t>(func_config.tosa_level))
Eric Kunze286f8342022-06-22 11:30:23 -070065 ("dump_intermediates", "Dump intermediate tensors (0/1)", cxxopts::value<uint32_t>(func_config.dump_intermediates))
Tai Lya4d748b2023-03-28 22:06:56 +000066 ("p,precise_mode", "Calculate floating point operations in FP64 (0/1)", cxxopts::value<uint32_t>(func_config.precise_mode))
Tai Ly47625642023-09-07 20:49:09 +000067 ("initialize_variable_tensor_from_numpy", "Initialize variable tensors from flatbuffer (0, default) or numpy (1)", cxxopts::value<uint32_t>(func_config.initialize_variable_tensor_from_numpy))
Eric Kunze286f8342022-06-22 11:30:23 -070068 ("v,version", "print model version")
69 ("i,input_tensor_file", "specify input tensor files", cxxopts::value<std::vector<std::string>>())
70 ("l,loglevel", func_debug.get_debug_verbosity_help_string(), cxxopts::value<std::string>())
71 ("o,logfile", "output log file", cxxopts::value<std::string>())
72 ("d,debugmask", func_debug.get_debug_mask_help_string(), cxxopts::value<std::vector<std::string>>())
73 ("h,help", "print help");
74 // clang-format on
75
76 auto result = options.parse(argc, argv);
Jerry Ge9c9c8da2023-07-19 23:08:16 +000077 if (result.count("help"))
78 {
Eric Kunze286f8342022-06-22 11:30:23 -070079 std::cout << options.help() << std::endl;
80 return 1;
Eric Kunzee5e26762020-10-13 16:11:07 -070081 }
Jerry Ge9c9c8da2023-07-19 23:08:16 +000082 if (result.count("debugmask"))
83 {
Eric Kunze286f8342022-06-22 11:30:23 -070084 auto& v = result["debugmask"].as<std::vector<std::string>>();
85 for (const std::string& s : v)
86 func_debug.set_mask(s);
Eric Kunzee5e26762020-10-13 16:11:07 -070087 }
Jerry Ge9c9c8da2023-07-19 23:08:16 +000088 if (result.count("loglevel"))
89 {
Eric Kunze286f8342022-06-22 11:30:23 -070090 const std::string& levelstr = result["loglevel"].as<std::string>();
91 func_debug.set_verbosity(levelstr);
92 }
Jerry Ge9c9c8da2023-07-19 23:08:16 +000093 if (result.count("logfile"))
94 {
Eric Kunze286f8342022-06-22 11:30:23 -070095 func_debug.set_file(result["logfile"].as<std::string>());
96 }
Jerry Ge9c9c8da2023-07-19 23:08:16 +000097 if (result.count("input_tensor_file"))
98 {
Eric Kunze286f8342022-06-22 11:30:23 -070099 func_config.ifm_name = result["input_tensor_file"].as<std::string>();
100 }
Jerry Ge9c9c8da2023-07-19 23:08:16 +0000101 if (result.count("version"))
102 {
Eric Kunze286f8342022-06-22 11:30:23 -0700103 std::cout << "Model version " << version << std::endl;
104 }
105 }
Jerry Ge9c9c8da2023-07-19 23:08:16 +0000106 catch (const std::exception& e)
Eric Kunze286f8342022-06-22 11:30:23 -0700107 {
108 std::cerr << e.what() << '\n';
109 return 1;
Eric Kunzee5e26762020-10-13 16:11:07 -0700110 }
111
112 return 0;
113}
114
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100115#endif