2022-01-19 01:07:49 +03:00
|
|
|
// Copyright (C) 2018-2022 Intel Corporation
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
//
|
|
|
|
|
|
2019-01-21 21:31:31 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <gflags/gflags.h>
|
2021-04-22 14:02:54 +03:00
|
|
|
|
2019-01-21 21:31:31 +03:00
|
|
|
#include <iostream>
|
2021-04-22 14:02:54 +03:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for help argument
|
|
|
|
|
static const char help_message[] = "Print a usage message.";
|
|
|
|
|
|
2021-12-06 11:00:58 +03:00
|
|
|
/// @brief message for input data argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char input_message[] =
|
|
|
|
|
"Required. Paths to input files. Example of usage: <file1.ark,file2.ark> or <file.ark> or <file.npz>.";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for model argument
|
|
|
|
|
static const char model_message[] = "Required. Path to an .xml file with a trained model (required if -rg is missing).";
|
|
|
|
|
|
2021-12-06 11:00:58 +03:00
|
|
|
/// @brief message for assigning calculation to device
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char target_device_message[] =
|
|
|
|
|
"Optional. Specify a target device to infer on. CPU, GPU, MYRIAD, GNA_AUTO, GNA_HW, "
|
|
|
|
|
"GNA_HW_WITH_SW_FBACK, GNA_SW_FP32, "
|
|
|
|
|
"GNA_SW_EXACT and HETERO with combination of GNA as the primary device and CPU"
|
|
|
|
|
" as a secondary (e.g. HETERO:GNA,CPU) are supported. "
|
|
|
|
|
"The sample will look for a suitable plugin for device specified.";
|
2019-04-12 18:25:53 +03:00
|
|
|
|
2021-05-07 12:02:49 +02:00
|
|
|
/// @brief message for execution target
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char execution_target_message[] =
|
|
|
|
|
"Optional. Specify GNA execution target generation. "
|
|
|
|
|
"May be one of GNA_TARGET_2_0, GNA_TARGET_3_0. "
|
|
|
|
|
"By default, generation corresponds to the GNA HW available in the system "
|
|
|
|
|
"or the latest fully supported generation by the software. "
|
|
|
|
|
"See the GNA Plugin's GNA_EXEC_TARGET config option description.";
|
2021-05-07 12:02:49 +02:00
|
|
|
|
2021-12-06 11:00:58 +03:00
|
|
|
/// @brief message for compile target
|
2021-05-07 12:02:49 +02:00
|
|
|
static const char compile_target_message[] = "Optional. Specify GNA compile target generation. "
|
|
|
|
|
"May be one of GNA_TARGET_2_0, GNA_TARGET_3_0. "
|
|
|
|
|
"By default, generation corresponds to the GNA HW available in the system "
|
|
|
|
|
"or the latest fully supported generation by the software. "
|
|
|
|
|
"See the GNA Plugin's GNA_COMPILE_TARGET config option description.";
|
|
|
|
|
|
2021-12-10 09:17:29 +01:00
|
|
|
/// @brief message for enabling GNA log
|
|
|
|
|
static const char enable_log_message[] = "Optional. Enable GNA logging, which may give additional info "
|
|
|
|
|
"about potential issues found in network. "
|
|
|
|
|
"By default logging is disabled.";
|
|
|
|
|
|
2019-01-21 21:31:31 +03:00
|
|
|
/// @brief message for performance counters
|
2021-04-15 13:42:46 +03:00
|
|
|
static const char performance_counter_message[] = "Optional. Enables per-layer performance report.";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for user library argument
|
2021-04-22 14:02:54 +03:00
|
|
|
static const char custom_cpu_library_message[] = "Required for CPU plugin custom layers."
|
|
|
|
|
"Absolute path to a shared library with the kernels implementations.";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for score output argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char output_message[] =
|
|
|
|
|
"Optional. Output file name to save scores. Example of usage: <output.ark> or <output.npz>";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for reference score file argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char reference_score_message[] =
|
|
|
|
|
"Optional. Read reference score file and compare scores. Example of usage: <reference.ark> or <reference.npz>";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for read GNA model argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char read_gna_model_message[] =
|
|
|
|
|
"Read GNA model from file using path/filename provided (required if -m is missing).";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for write GNA model argument
|
2021-04-15 13:42:46 +03:00
|
|
|
static const char write_gna_model_message[] = "Optional. Write GNA model to file using path/filename provided.";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for write GNA embedded model argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char write_embedded_model_message[] =
|
|
|
|
|
"Optional. Write GNA embedded model to file using path/filename provided.";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
2020-02-11 22:48:49 +03:00
|
|
|
/// @brief message for write GNA embedded model generation argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char write_embedded_model_generation_message[] =
|
|
|
|
|
"Optional. GNA generation configuration string for embedded export."
|
|
|
|
|
"Can be GNA1 (default) or GNA3.";
|
2020-02-11 22:48:49 +03:00
|
|
|
|
2019-01-21 21:31:31 +03:00
|
|
|
/// @brief message for quantization argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char quantization_message[] =
|
|
|
|
|
"Optional. Input quantization mode: static (default), dynamic, or user (use with -sf).";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for quantization bits argument
|
2021-04-15 13:42:46 +03:00
|
|
|
static const char quantization_bits_message[] = "Optional. Weight bits for quantization: 8 or 16 (default)";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for scale factor argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char scale_factor_message[] =
|
|
|
|
|
"Optional. User-specified input scale factor for quantization (use with -q user). "
|
|
|
|
|
"If the network contains multiple inputs, provide scale factors by separating them with "
|
2022-02-16 13:23:50 +03:00
|
|
|
"commas. "
|
|
|
|
|
"For example: <input_name1>:<sf1>,<input_name2>:<sf2> or just <sf> to be applied to all inputs";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for batch size argument
|
2021-04-15 13:42:46 +03:00
|
|
|
static const char batch_size_message[] = "Optional. Batch size 1-8 (default 1)";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief message for #threads for CPU inference
|
2021-04-22 14:02:54 +03:00
|
|
|
static const char infer_num_threads_message[] = "Optional. Number of threads to use for concurrent async"
|
|
|
|
|
" inference requests on the GNA.";
|
2019-01-21 21:31:31 +03:00
|
|
|
|
2019-08-09 19:02:42 +03:00
|
|
|
/// @brief message for left context window argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char context_window_message_l[] =
|
|
|
|
|
"Optional. Number of frames for left context windows (default is 0). "
|
|
|
|
|
"Works only with context window networks."
|
2022-01-14 12:20:36 +03:00
|
|
|
" If you use the cw_l or cw_r flag, then batch size argument is ignored.";
|
2019-08-09 19:02:42 +03:00
|
|
|
|
|
|
|
|
/// @brief message for right context window argument
|
2021-08-11 14:47:29 +03:00
|
|
|
static const char context_window_message_r[] =
|
|
|
|
|
"Optional. Number of frames for right context windows (default is 0). "
|
|
|
|
|
"Works only with context window networks."
|
2022-01-14 12:20:36 +03:00
|
|
|
" If you use the cw_r or cw_l flag, then batch size argument is ignored.";
|
2019-04-12 18:25:53 +03:00
|
|
|
|
2020-10-16 15:34:22 +03:00
|
|
|
/// @brief message for output layer names
|
2021-04-22 14:02:54 +03:00
|
|
|
static const char output_layer_names_message[] = "Optional. Layer names for output blobs. "
|
|
|
|
|
"The names are separated with \",\" "
|
|
|
|
|
"Example: Output1:port,Output2:port ";
|
2020-10-16 15:34:22 +03:00
|
|
|
|
|
|
|
|
/// @brief message for inputs layer names
|
2021-04-22 14:02:54 +03:00
|
|
|
static const char input_layer_names_message[] = "Optional. Layer names for input blobs. "
|
|
|
|
|
"The names are separated with \",\" "
|
|
|
|
|
"Example: Input1,Input2 ";
|
2022-02-17 16:11:57 +03:00
|
|
|
/// @brief message for inputs layer names
|
|
|
|
|
static const char layout_message[] =
|
|
|
|
|
"Optional. Prompts how network layouts should be treated by application. "
|
|
|
|
|
"For example, \"input1[NCHW],input2[NC]\" or \"[NCHW]\" in case of one input size.";
|
|
|
|
|
;
|
2020-10-16 15:34:22 +03:00
|
|
|
|
2021-03-04 14:10:01 +01:00
|
|
|
/// @brief message for PWL max error percent
|
2021-04-22 14:02:54 +03:00
|
|
|
static const char pwl_max_error_percent_message[] = "Optional. The maximum percent of error for PWL function."
|
2021-03-04 14:10:01 +01:00
|
|
|
"The value must be in <0, 100> range. The default value is 1.0.";
|
|
|
|
|
|
2019-01-21 21:31:31 +03:00
|
|
|
/// \brief Define flag for showing help message <br>
|
|
|
|
|
DEFINE_bool(h, false, help_message);
|
|
|
|
|
|
|
|
|
|
/// \brief Define parameter for set image file <br>
|
|
|
|
|
/// It is a required parameter
|
|
|
|
|
DEFINE_string(i, "", input_message);
|
|
|
|
|
|
|
|
|
|
/// \brief Define parameter for set model file <br>
|
|
|
|
|
/// It is a required parameter
|
|
|
|
|
DEFINE_string(m, "", model_message);
|
|
|
|
|
|
2021-04-15 13:42:46 +03:00
|
|
|
/// \brief device the target device to infer on (default CPU) <br>
|
2021-02-08 15:13:11 +03:00
|
|
|
DEFINE_string(d, "CPU", target_device_message);
|
2019-01-21 21:31:31 +03:00
|
|
|
|
2021-05-07 12:02:49 +02:00
|
|
|
/// \brief GNA execution target <br>
|
|
|
|
|
DEFINE_string(exec_target, "", execution_target_message);
|
|
|
|
|
|
|
|
|
|
/// \brief GNA compile target <br>
|
|
|
|
|
DEFINE_string(compile_target, "", compile_target_message);
|
|
|
|
|
|
2021-12-10 09:17:29 +01:00
|
|
|
/// \brief GNA log level (default LOG_NONE) <br>
|
|
|
|
|
DEFINE_string(log, "LOG_NONE", enable_log_message);
|
|
|
|
|
|
2019-01-21 21:31:31 +03:00
|
|
|
/// \brief Enable per-layer performance report
|
|
|
|
|
DEFINE_bool(pc, false, performance_counter_message);
|
|
|
|
|
|
2021-04-15 13:42:46 +03:00
|
|
|
/// @brief Write output file to save ark scores
|
2019-01-21 21:31:31 +03:00
|
|
|
DEFINE_string(o, "", output_message);
|
|
|
|
|
|
|
|
|
|
/// @brief Read reference score file
|
|
|
|
|
DEFINE_string(r, "", reference_score_message);
|
|
|
|
|
|
|
|
|
|
/// @brief Read GNA model from file (model.bin)
|
|
|
|
|
DEFINE_string(rg, "", read_gna_model_message);
|
|
|
|
|
|
|
|
|
|
/// @brief Write GNA model to file (model.bin)
|
|
|
|
|
DEFINE_string(wg, "", write_gna_model_message);
|
|
|
|
|
|
|
|
|
|
/// @brief Write GNA embedded model to file (model.bin)
|
|
|
|
|
DEFINE_string(we, "", write_embedded_model_message);
|
|
|
|
|
|
|
|
|
|
/// @brief Input quantization mode (default static)
|
|
|
|
|
DEFINE_string(q, "static", quantization_message);
|
|
|
|
|
|
|
|
|
|
/// @brief Input quantization bits (default 16)
|
|
|
|
|
DEFINE_int32(qb, 16, quantization_bits_message);
|
|
|
|
|
|
2021-04-15 13:42:46 +03:00
|
|
|
/// @brief Scale factor for quantization
|
2020-06-09 14:36:28 +03:00
|
|
|
DEFINE_string(sf, "", scale_factor_message);
|
2019-01-21 21:31:31 +03:00
|
|
|
|
2022-02-17 16:11:57 +03:00
|
|
|
/// @brief Batch size (default 0)
|
|
|
|
|
DEFINE_int32(bs, 0, batch_size_message);
|
2019-01-21 21:31:31 +03:00
|
|
|
|
|
|
|
|
/// @brief Number of threads to use for inference on the CPU (also affects Hetero cases)
|
|
|
|
|
DEFINE_int32(nthreads, 1, infer_num_threads_message);
|
|
|
|
|
|
2019-08-09 19:02:42 +03:00
|
|
|
/// @brief Right context window size (default 0)
|
|
|
|
|
DEFINE_int32(cw_r, 0, context_window_message_r);
|
|
|
|
|
|
|
|
|
|
/// @brief Left context window size (default 0)
|
|
|
|
|
DEFINE_int32(cw_l, 0, context_window_message_l);
|
2019-04-12 18:25:53 +03:00
|
|
|
|
2020-10-16 15:34:22 +03:00
|
|
|
/// @brief Output layer name
|
|
|
|
|
DEFINE_string(oname, "", output_layer_names_message);
|
|
|
|
|
|
|
|
|
|
/// @brief Input layer name
|
|
|
|
|
DEFINE_string(iname, "", input_layer_names_message);
|
|
|
|
|
|
2022-02-17 16:11:57 +03:00
|
|
|
/// @brief Input layer name
|
|
|
|
|
DEFINE_string(layout, "", layout_message);
|
|
|
|
|
|
2021-03-04 14:10:01 +01:00
|
|
|
/// @brief PWL max error percent
|
|
|
|
|
DEFINE_double(pwl_me, 1.0, pwl_max_error_percent_message);
|
|
|
|
|
|
2019-01-21 21:31:31 +03:00
|
|
|
/**
|
|
|
|
|
* \brief This function show a help message
|
|
|
|
|
*/
|
2022-01-19 01:08:07 +03:00
|
|
|
static void show_usage() {
|
2019-01-21 21:31:31 +03:00
|
|
|
std::cout << std::endl;
|
|
|
|
|
std::cout << "speech_sample [OPTION]" << std::endl;
|
|
|
|
|
std::cout << "Options:" << std::endl;
|
|
|
|
|
std::cout << std::endl;
|
2021-12-21 07:44:06 +01:00
|
|
|
std::cout << " -h " << help_message << std::endl;
|
|
|
|
|
std::cout << " -i \"<path>\" " << input_message << std::endl;
|
|
|
|
|
std::cout << " -m \"<path>\" " << model_message << std::endl;
|
|
|
|
|
std::cout << " -o \"<path>\" " << output_message << std::endl;
|
|
|
|
|
std::cout << " -d \"<device>\" " << target_device_message << std::endl;
|
|
|
|
|
std::cout << " -pc " << performance_counter_message << std::endl;
|
|
|
|
|
std::cout << " -q \"<mode>\" " << quantization_message << std::endl;
|
|
|
|
|
std::cout << " -qb \"<integer>\" " << quantization_bits_message << std::endl;
|
|
|
|
|
std::cout << " -sf \"<double>\" " << scale_factor_message << std::endl;
|
|
|
|
|
std::cout << " -bs \"<integer>\" " << batch_size_message << std::endl;
|
|
|
|
|
std::cout << " -r \"<path>\" " << reference_score_message << std::endl;
|
|
|
|
|
std::cout << " -rg \"<path>\" " << read_gna_model_message << std::endl;
|
|
|
|
|
std::cout << " -wg \"<path>\" " << write_gna_model_message << std::endl;
|
|
|
|
|
std::cout << " -we \"<path>\" " << write_embedded_model_message << std::endl;
|
|
|
|
|
std::cout << " -cw_l \"<integer>\" " << context_window_message_l << std::endl;
|
|
|
|
|
std::cout << " -cw_r \"<integer>\" " << context_window_message_r << std::endl;
|
|
|
|
|
std::cout << " -oname \"<string>\" " << output_layer_names_message << std::endl;
|
|
|
|
|
std::cout << " -iname \"<string>\" " << input_layer_names_message << std::endl;
|
2022-02-17 16:11:57 +03:00
|
|
|
std::cout << " -layout \"<string>\" " << layout_message << std::endl;
|
2021-12-21 07:44:06 +01:00
|
|
|
std::cout << " -pwl_me \"<double>\" " << pwl_max_error_percent_message << std::endl;
|
|
|
|
|
std::cout << " -exec_target \"<string>\" " << execution_target_message << std::endl;
|
|
|
|
|
std::cout << " -compile_target \"<string>\" " << compile_target_message << std::endl;
|
2019-01-21 21:31:31 +03:00
|
|
|
}
|
2021-12-19 20:56:40 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Checks input arguments
|
|
|
|
|
* @param argc number of args
|
|
|
|
|
* @param argv list of input arguments
|
|
|
|
|
* @return bool status true(Success) or false(Fail)
|
|
|
|
|
*/
|
2022-01-19 01:08:07 +03:00
|
|
|
bool parse_and_check_command_line(int argc, char* argv[]) {
|
2021-12-19 20:56:40 +03:00
|
|
|
slog::info << "Parsing input parameters" << slog::endl;
|
|
|
|
|
|
|
|
|
|
gflags::ParseCommandLineNonHelpFlags(&argc, &argv, true);
|
|
|
|
|
if (FLAGS_h) {
|
2022-01-19 01:08:07 +03:00
|
|
|
show_usage();
|
2021-12-19 20:56:40 +03:00
|
|
|
showAvailableDevices();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool isDumpMode = !FLAGS_wg.empty() || !FLAGS_we.empty();
|
|
|
|
|
|
|
|
|
|
// input not required only in dump mode and if external scale factor provided
|
|
|
|
|
if (FLAGS_i.empty() && (!isDumpMode || FLAGS_q.compare("user") != 0)) {
|
2022-01-19 01:08:07 +03:00
|
|
|
show_usage();
|
2021-12-19 20:56:40 +03:00
|
|
|
if (isDumpMode) {
|
|
|
|
|
throw std::logic_error("In model dump mode either static quantization is used (-i) or user scale"
|
|
|
|
|
" factor need to be provided. See -q user option");
|
|
|
|
|
}
|
|
|
|
|
throw std::logic_error("Input file not set. Please use -i.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FLAGS_m.empty() && FLAGS_rg.empty()) {
|
2022-01-19 01:08:07 +03:00
|
|
|
show_usage();
|
2021-12-19 20:56:40 +03:00
|
|
|
throw std::logic_error("Either IR file (-m) or GNAModel file (-rg) need to be set.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((!FLAGS_m.empty() && !FLAGS_rg.empty())) {
|
|
|
|
|
throw std::logic_error("Only one of -m and -rg is allowed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> supportedDevices = {"CPU",
|
|
|
|
|
"GPU",
|
|
|
|
|
"GNA_AUTO",
|
|
|
|
|
"GNA_HW",
|
|
|
|
|
"GNA_HW_WITH_SW_FBACK",
|
|
|
|
|
"GNA_SW_EXACT",
|
|
|
|
|
"GNA_SW_FP32",
|
|
|
|
|
"HETERO:GNA,CPU",
|
|
|
|
|
"HETERO:GNA_HW,CPU",
|
|
|
|
|
"HETERO:GNA_SW_EXACT,CPU",
|
|
|
|
|
"HETERO:GNA_SW_FP32,CPU",
|
|
|
|
|
"MYRIAD"};
|
|
|
|
|
|
|
|
|
|
if (std::find(supportedDevices.begin(), supportedDevices.end(), FLAGS_d) == supportedDevices.end()) {
|
|
|
|
|
throw std::logic_error("Specified device is not supported.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t batchSize = (uint32_t)FLAGS_bs;
|
2022-02-17 16:11:57 +03:00
|
|
|
if (batchSize && ((batchSize < 1) || (batchSize > 8))) {
|
2021-12-19 20:56:40 +03:00
|
|
|
throw std::logic_error("Batch size out of range (1..8).");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** default is a static quantization **/
|
|
|
|
|
if ((FLAGS_q.compare("static") != 0) && (FLAGS_q.compare("dynamic") != 0) && (FLAGS_q.compare("user") != 0)) {
|
|
|
|
|
throw std::logic_error("Quantization mode not supported (static, dynamic, user).");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FLAGS_q.compare("dynamic") == 0) {
|
|
|
|
|
throw std::logic_error("Dynamic quantization not yet supported.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FLAGS_qb != 16 && FLAGS_qb != 8) {
|
|
|
|
|
throw std::logic_error("Only 8 or 16 bits supported.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FLAGS_cw_r < 0) {
|
|
|
|
|
throw std::logic_error("Invalid value for 'cw_r' argument. It must be greater than or equal to 0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FLAGS_cw_l < 0) {
|
|
|
|
|
throw std::logic_error("Invalid value for 'cw_l' argument. It must be greater than or equal to 0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (FLAGS_pwl_me < 0.0 || FLAGS_pwl_me > 100.0) {
|
|
|
|
|
throw std::logic_error("Invalid value for 'pwl_me' argument. It must be greater than 0.0 and less than 100.0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|