| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #ifndef TENSORRT_ARGS_PARSER_H |
| | #define TENSORRT_ARGS_PARSER_H |
| |
|
| | #ifdef _MSC_VER |
| | #include "getOptWin.h" |
| | #else |
| | #include <getopt.h> |
| | #endif |
| | #include <iostream> |
| | #include <string> |
| | #include <vector> |
| |
|
| | namespace samplesCommon |
| | { |
| |
|
| | |
| | |
| | |
| | |
| | struct SampleParams |
| | { |
| | int32_t batchSize{1}; |
| | int32_t dlaCore{-1}; |
| | bool int8{false}; |
| | bool fp16{false}; |
| | bool bf16{false}; |
| | std::vector<std::string> dataDirs; |
| | std::vector<std::string> inputTensorNames; |
| | std::vector<std::string> outputTensorNames; |
| | std::string timingCacheFile; |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | struct OnnxSampleParams : public SampleParams |
| | { |
| | std::string onnxFileName; |
| | }; |
| |
|
| | |
| | |
| | |
| | struct Args |
| | { |
| | bool runInInt8{false}; |
| | bool runInFp16{false}; |
| | bool runInBf16{false}; |
| | bool help{false}; |
| | int32_t useDLACore{-1}; |
| | int32_t batch{1}; |
| | std::vector<std::string> dataDirs; |
| | std::string saveEngine; |
| | std::string loadEngine; |
| | bool rowOrder{true}; |
| | std::string timingCacheFile; |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | inline bool parseArgs(Args& args, int32_t argc, char* argv[]) |
| | { |
| | while (1) |
| | { |
| | int32_t arg; |
| | static struct option long_options[] |
| | = {{"help", no_argument, 0, 'h'}, {"datadir", required_argument, 0, 'd'}, {"int8", no_argument, 0, 'i'}, |
| | {"fp16", no_argument, 0, 'f'}, {"bf16", no_argument, 0, 'z'}, {"columnOrder", no_argument, 0, 'c'}, |
| | {"saveEngine", required_argument, 0, 's'}, {"loadEngine", required_argument, 0, 'o'}, |
| | {"useDLACore", required_argument, 0, 'u'}, {"batch", required_argument, 0, 'b'}, |
| | {"timingCacheFile", required_argument, 0, 't'}, {nullptr, 0, nullptr, 0}}; |
| | int32_t option_index = 0; |
| | arg = getopt_long(argc, argv, "hd:iu", long_options, &option_index); |
| | if (arg == -1) |
| | { |
| | break; |
| | } |
| |
|
| | switch (arg) |
| | { |
| | case 'h': args.help = true; return true; |
| | case 'd': |
| | if (optarg) |
| | { |
| | args.dataDirs.push_back(optarg); |
| | } |
| | else |
| | { |
| | std::cerr << "ERROR: --datadir requires option argument" << std::endl; |
| | return false; |
| | } |
| | break; |
| | case 's': |
| | if (optarg) |
| | { |
| | args.saveEngine = optarg; |
| | } |
| | break; |
| | case 'o': |
| | if (optarg) |
| | { |
| | args.loadEngine = optarg; |
| | } |
| | break; |
| | case 'i': args.runInInt8 = true; break; |
| | case 'f': args.runInFp16 = true; break; |
| | case 'z': args.runInBf16 = true; break; |
| | case 'c': args.rowOrder = false; break; |
| | case 'u': |
| | if (optarg) |
| | { |
| | args.useDLACore = std::stoi(optarg); |
| | } |
| | break; |
| | case 'b': |
| | if (optarg) |
| | { |
| | args.batch = std::stoi(optarg); |
| | } |
| | break; |
| | case 't': |
| | if (optarg) |
| | { |
| | args.timingCacheFile = optarg; |
| | } |
| | else |
| | { |
| | std::cerr << "ERROR: --timingCacheFile requires option argument" << std::endl; |
| | return false; |
| | } |
| | break; |
| | default: return false; |
| | } |
| | } |
| | return true; |
| | } |
| |
|
| | } |
| |
|
| | #endif |
| |
|