int num_thread = -1; // -1 means "auto"
// Read command-line arguments
- //
- // The current implementation works only for command-line arguments of the following form:
- //
- // --model <path/to/tflite> --record-count N --thread auto --nnapi --csv-report <path/to/csv>
- //
- // TODD Parse command-line arguments
- auto arg = [argc, argv](uint32_t n) { return std::string{argv[n]}; };
-
- assert(argc == 10);
- assert(arg(1) == "--model");
- {
- model_path = arg(2);
+ std::map<std::string, std::function<uint32_t(const char *const *)>> opts;
+
+ opts["--model"] = [&model_path, &model_path_initialized](const char *const *tok) {
+ model_path = std::string{tok[0]};
model_path_initialized = true;
- }
- assert(arg(3) == "--record-count");
- {
- record_count = std::stoi(arg(4));
- }
- assert(arg(5) == "--thread");
- assert(arg(6) == "auto");
- assert(arg(7) == "--nnapi");
- {
+ return 1; // # of arguments
+ };
+
+ opts["--record-count"] = [&record_count](const char *const *tok) {
+ record_count = std::stoi(tok[0]);
+ return 1; // # of arguments
+ };
+
+ opts["--thread"] = [](const char *const *tok) {
+ assert(std::string{tok[0]} == "auto");
+ return 1;
+ };
+
+ opts["--nnapi"] = [&session_type](const char *const *) {
session_type = SessionType::NNAPI;
- }
- assert(arg(8) == "--csv-report");
+ return 0;
+ };
+
+ opts["--csv-report"] = [&observer](const char *const *tok) {
+ observer.append(nnfw::cpp14::make_unique<mlapse::CSVReportGenerator>(tok[0]));
+ return 1;
+ };
+
{
- observer.append(nnfw::cpp14::make_unique<mlapse::CSVReportGenerator>(arg(9)));
+ uint32_t offset = 1;
+
+ while (offset < argc)
+ {
+ auto opt = argv[offset];
+
+ auto it = opts.find(opt);
+
+ if (it == opts.end())
+ {
+ std::cout << "INVALID OPTION: " << opt << std::endl;
+ return 255;
+ }
+
+ auto func = it->second;
+
+ auto num_skip = func(argv + offset + 1);
+
+ offset += 1;
+ offset += num_skip;
+ }
}
// Check arguments