Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
Jared Smolens | 62a7b7f | 2022-03-19 05:42:27 +0000 | [diff] [blame] | 2 | // Copyright (c) 2020-2022, ARM Limited. |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 3 | // |
| 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 Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 16 | #ifndef COMMAND_LINE_UTILS_H_ |
| 17 | #define COMMAND_LINE_UTILS_H_ |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 18 | |
| 19 | #include "func_config.h" |
| 20 | #include "func_debug.h" |
| 21 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | #include <cxxopts.hpp> |
| 24 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 25 | // Read the command line arguments |
Kevin Cheng | 1009674 | 2021-10-20 19:51:41 +0000 | [diff] [blame] | 26 | int func_model_parse_cmd_line( |
Eric Kunze | 286f834 | 2022-06-22 11:30:23 -0700 | [diff] [blame] | 27 | func_config_t& func_config, func_debug_t& func_debug, int argc, char** argv, const char* version) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 28 | { |
Eric Kunze | 286f834 | 2022-06-22 11:30:23 -0700 | [diff] [blame] | 29 | try |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 30 | { |
Eric Kunze | 286f834 | 2022-06-22 11:30:23 -0700 | [diff] [blame] | 31 | 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)) |
| 51 | ("eval", "Evaluate the network (0/1)", cxxopts::value<uint32_t>(func_config.eval)) |
| 52 | ("fp_format", "Floating-point number dump format string (printf-style format, e.g. 0.5)", |
| 53 | cxxopts::value<std::string>(func_config.fp_format)) |
| 54 | ("validate_only", "Validate the network, but do not read inputs or evaluate (0/1)", |
| 55 | cxxopts::value<uint32_t>(func_config.validate_only)) |
| 56 | ("output_tensors", "Output tensors to a file (0/1)", cxxopts::value<uint32_t>(func_config.output_tensors)) |
| 57 | ("tosa_profile", "Set TOSA profile (0 = Base Inference, 1 = Main Inference, 2 = Main Training)", |
| 58 | cxxopts::value<uint32_t>(func_config.tosa_profile)) |
| 59 | ("dump_intermediates", "Dump intermediate tensors (0/1)", cxxopts::value<uint32_t>(func_config.dump_intermediates)) |
| 60 | ("v,version", "print model version") |
| 61 | ("i,input_tensor_file", "specify input tensor files", cxxopts::value<std::vector<std::string>>()) |
| 62 | ("l,loglevel", func_debug.get_debug_verbosity_help_string(), cxxopts::value<std::string>()) |
| 63 | ("o,logfile", "output log file", cxxopts::value<std::string>()) |
| 64 | ("d,debugmask", func_debug.get_debug_mask_help_string(), cxxopts::value<std::vector<std::string>>()) |
| 65 | ("h,help", "print help"); |
| 66 | // clang-format on |
| 67 | |
| 68 | auto result = options.parse(argc, argv); |
| 69 | if (result.count("help")) { |
| 70 | std::cout << options.help() << std::endl; |
| 71 | return 1; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 72 | } |
Eric Kunze | 286f834 | 2022-06-22 11:30:23 -0700 | [diff] [blame] | 73 | if (result.count("debugmask")) { |
| 74 | auto& v = result["debugmask"].as<std::vector<std::string>>(); |
| 75 | for (const std::string& s : v) |
| 76 | func_debug.set_mask(s); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 77 | } |
Eric Kunze | 286f834 | 2022-06-22 11:30:23 -0700 | [diff] [blame] | 78 | if (result.count("loglevel")) { |
| 79 | const std::string& levelstr = result["loglevel"].as<std::string>(); |
| 80 | func_debug.set_verbosity(levelstr); |
| 81 | } |
| 82 | if (result.count("logfile")) { |
| 83 | func_debug.set_file(result["logfile"].as<std::string>()); |
| 84 | } |
| 85 | if (result.count("input_tensor_file")) { |
| 86 | func_config.ifm_name = result["input_tensor_file"].as<std::string>(); |
| 87 | } |
| 88 | if (result.count("version")) { |
| 89 | std::cout << "Model version " << version << std::endl; |
| 90 | } |
| 91 | } |
| 92 | catch(const std::exception& e) |
| 93 | { |
| 94 | std::cerr << e.what() << '\n'; |
| 95 | return 1; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 101 | #endif |