| 1031 | }; |
| 1032 | |
| 1033 | static test_args parse_cli(int argc, char ** argv) { |
| 1034 | test_args out; |
| 1035 | |
| 1036 | for (int i = 1; i < argc; ++i) { |
| 1037 | const char * arg = argv[i]; |
| 1038 | |
| 1039 | if (std::strcmp(arg, "--test") == 0) { |
| 1040 | if (i + 1 >= argc) { |
| 1041 | fprintf(stderr, "--test expects a value\n"); |
| 1042 | exit(EXIT_FAILURE); |
| 1043 | } |
| 1044 | out.test = argv[++i]; |
| 1045 | continue; |
| 1046 | } |
| 1047 | if (std::strncmp(arg, "--test=", 7) == 0) { |
| 1048 | out.test = arg + 7; |
| 1049 | continue; |
| 1050 | } |
| 1051 | if (std::strcmp(arg, "--model") == 0) { |
| 1052 | if (i + 1 >= argc) { |
| 1053 | fprintf(stderr, "--model expects a value\n"); |
| 1054 | exit(EXIT_FAILURE); |
| 1055 | } |
| 1056 | out.model = argv[++i]; |
| 1057 | continue; |
| 1058 | } |
| 1059 | if (std::strncmp(arg, "--model=", 8) == 0) { |
| 1060 | out.model = arg + 8; |
| 1061 | continue; |
| 1062 | } |
| 1063 | if (std::strcmp(arg, "--device") == 0) { |
| 1064 | if (i + 1 >= argc) { |
| 1065 | fprintf(stderr, "--device expects a value (cpu or gpu)\n"); |
| 1066 | exit(EXIT_FAILURE); |
| 1067 | } |
| 1068 | out.device = argv[++i]; |
| 1069 | continue; |
| 1070 | } |
| 1071 | if (std::strncmp(arg, "--device=", 9) == 0) { |
| 1072 | out.device = arg + 9; |
| 1073 | continue; |
| 1074 | } |
| 1075 | if (out.model.empty()) { |
| 1076 | out.model = arg; |
| 1077 | continue; |
| 1078 | } |
| 1079 | |
| 1080 | fprintf(stderr, "Unexpected argument: %s\n", arg); |
| 1081 | exit(EXIT_FAILURE); |
| 1082 | } |
| 1083 | |
| 1084 | if (out.device != "cpu" && out.device != "gpu" && out.device != "auto") { |
| 1085 | fprintf(stderr, "Invalid device '%s'. Must be 'cpu', 'gpu' or 'auto'\n", out.device.c_str()); |
| 1086 | exit(EXIT_FAILURE); |
| 1087 | } |
| 1088 | |
| 1089 | return out; |
| 1090 | } |