\brief Populates the Args struct with the provided command-line parameters. \throw invalid_argument if any of the arguments are not valid \return boolean If return value is true, execution can continue, otherwise program should exit
| 97 | //! \return boolean If return value is true, execution can continue, otherwise program should exit |
| 98 | //! |
| 99 | inline bool parseArgs(Args& args, int32_t argc, char* argv[]) |
| 100 | { |
| 101 | while (1) |
| 102 | { |
| 103 | int32_t arg; |
| 104 | static struct option long_options[] = {{"help", no_argument, 0, 'h'}, {"datadir", required_argument, 0, 'd'}, |
| 105 | {"int8", no_argument, 0, 'i'}, {"fp16", no_argument, 0, 'f'}, {"useILoop", no_argument, 0, 'l'}, |
| 106 | {"saveEngine", required_argument, 0, 's'}, {"loadEngine", required_argument, 0, 'o'}, |
| 107 | {"useDLACore", required_argument, 0, 'u'}, {"batch", required_argument, 0, 'b'}, {nullptr, 0, nullptr, 0}}; |
| 108 | int32_t option_index = 0; |
| 109 | arg = getopt_long(argc, argv, "hd:iu", long_options, &option_index); |
| 110 | if (arg == -1) |
| 111 | { |
| 112 | break; |
| 113 | } |
| 114 | |
| 115 | switch (arg) |
| 116 | { |
| 117 | case 'h': args.help = true; return true; |
| 118 | case 'd': |
| 119 | if (optarg) |
| 120 | { |
| 121 | args.dataDirs.push_back(optarg); |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | std::cerr << "ERROR: --datadir requires option argument" << std::endl; |
| 126 | return false; |
| 127 | } |
| 128 | break; |
| 129 | case 's': |
| 130 | if (optarg) |
| 131 | { |
| 132 | args.saveEngine = optarg; |
| 133 | } |
| 134 | break; |
| 135 | case 'o': |
| 136 | if (optarg) |
| 137 | { |
| 138 | args.loadEngine = optarg; |
| 139 | } |
| 140 | break; |
| 141 | case 'i': args.runInInt8 = true; break; |
| 142 | case 'f': args.runInFp16 = true; break; |
| 143 | case 'l': args.useILoop = true; break; |
| 144 | case 'u': |
| 145 | if (optarg) |
| 146 | { |
| 147 | args.useDLACore = std::stoi(optarg); |
| 148 | } |
| 149 | break; |
| 150 | case 'b': |
| 151 | if (optarg) |
| 152 | { |
| 153 | args.batch = std::stoi(optarg); |
| 154 | } |
| 155 | break; |
| 156 | default: return false; |