changed C++ samples due to OpenVINO style (#9463)

I'll merge this. We need to talk with someone who know openvino build system better than we to "use cmake function ov_ncc_style_check to perform such check automatically". As far as I can see, currently it used only in one place, so it is not common approach for openvino components
This commit is contained in:
Maxim Gordeev 2021-12-29 15:36:33 +03:00 committed by GitHub
parent 010877d06c
commit 39a1b98799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 189 additions and 191 deletions

View File

@ -45,7 +45,7 @@ DEFINE_string(d, "CPU", target_device_message);
/**
* @brief This function show a help message
*/
static void showUsage() {
static void show_usage() {
std::cout << std::endl;
std::cout << "classification_sample_async [OPTION]" << std::endl;
std::cout << "Options:" << std::endl;

View File

@ -40,22 +40,22 @@ using namespace ov::preprocess;
* @param argv list of input arguments
* @return bool status true(Success) or false(Fail)
*/
bool ParseAndCheckCommandLine(int argc, char* argv[]) {
bool parse_and_check_command_line(int argc, char* argv[]) {
gflags::ParseCommandLineNonHelpFlags(&argc, &argv, true);
if (FLAGS_h) {
showUsage();
show_usage();
showAvailableDevices();
return false;
}
slog::info << "Parsing input parameters" << slog::endl;
if (FLAGS_m.empty()) {
showUsage();
show_usage();
throw std::logic_error("Model is required but not set. Please set -m option.");
}
if (FLAGS_i.empty()) {
showUsage();
show_usage();
throw std::logic_error("Input is required but not set. Please set -i option.");
}
@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {
slog::info << ov::get_openvino_version() << slog::endl;
// -------- Parsing and validation of input arguments --------
if (!ParseAndCheckCommandLine(argc, argv)) {
if (!parse_and_check_command_line(argc, argv)) {
return EXIT_SUCCESS;
}

View File

@ -37,7 +37,7 @@ using namespace ov::preprocess;
* @param string of image size in WIDTHxHEIGHT format
* @return parsed width and height
*/
std::pair<size_t, size_t> parseImageSize(const std::string& size_string) {
std::pair<size_t, size_t> parse_image_size(const std::string& size_string) {
auto delimiter_pos = size_string.find("x");
if (delimiter_pos == std::string::npos || delimiter_pos >= size_string.size() - 1 || delimiter_pos == 0) {
std::stringstream err;
@ -81,7 +81,7 @@ int main(int argc, char* argv[]) {
const std::string image_path{argv[2]};
size_t input_width = 0;
size_t input_height = 0;
std::tie(input_width, input_height) = parseImageSize(argv[3]);
std::tie(input_width, input_height) = parse_image_size(argv[3]);
const std::string device_name{argv[4]};
// -----------------------------------------------------------------------------------------------------

View File

@ -16,13 +16,12 @@
#include "samples/slog.hpp"
// clang-format on
namespace {
/**
* @brief Print IE Parameters
* @param reference on IE Parameter
* @return void
*/
void printAnyValue(const ov::Any& value) {
void print_any_value(const ov::Any& value) {
if (value.empty()) {
slog::info << "EMPTY VALUE" << slog::endl;
} else if (value.is<bool>()) {
@ -84,8 +83,6 @@ void printAnyValue(const ov::Any& value) {
}
}
} // namespace
int main(int argc, char* argv[]) {
try {
// -------- Get OpenVINO runtime version --------
@ -114,7 +111,7 @@ int main(int argc, char* argv[]) {
for (auto&& metricName : supportedMetrics) {
if (metricName != METRIC_KEY(SUPPORTED_METRICS) && metricName != METRIC_KEY(SUPPORTED_CONFIG_KEYS)) {
slog::info << "\t\t" << metricName << " : " << slog::flush;
printAnyValue(core.get_metric(device, metricName));
print_any_value(core.get_metric(device, metricName));
}
}
@ -126,7 +123,7 @@ int main(int argc, char* argv[]) {
core.get_metric(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS));
for (auto&& configKey : supportedConfigKeys) {
slog::info << "\t\t" << configKey << " : " << slog::flush;
printAnyValue(core.get_config(device, configKey));
print_any_value(core.get_config(device, configKey));
}
}

View File

@ -4,10 +4,10 @@
#include "fileutils.hpp"
void ArkFile::GetFileInfo(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) {
void ArkFile::get_file_info(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) {
uint32_t numArrays = 0;
uint32_t numMemoryBytes = 0;
@ -34,7 +34,7 @@ void ArkFile::GetFileInfo(const char* fileName,
}
in_file.close();
} else {
throw std::runtime_error(std::string("Failed to open %s for reading in GetFileInfo()!\n") + fileName);
throw std::runtime_error(std::string("Failed to open %s for reading in get_file_info()!\n") + fileName);
}
if (ptrNumArrays != NULL)
@ -43,13 +43,13 @@ void ArkFile::GetFileInfo(const char* fileName,
*ptrNumMemoryBytes = numMemoryBytes;
}
void ArkFile::LoadFile(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) {
void ArkFile::load_file(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) {
std::ifstream in_file(fileName, std::ios::binary);
if (in_file.good()) {
uint32_t i = 0;
@ -72,7 +72,7 @@ void ArkFile::LoadFile(const char* fileName,
std::getline(in_file, ptrName, '\0'); // read variable length name followed by space and NUL
std::getline(in_file, line, '\4'); // read "BFM" followed by space and control-D
if (line.compare("BFM ") != 0) {
throw std::runtime_error(std::string("Cannot find array specifier in file %s in LoadFile()!\n") +
throw std::runtime_error(std::string("Cannot find array specifier in file %s in load_file()!\n") +
fileName);
}
in_file.read(reinterpret_cast<char*>(ptrNumRows), sizeof(uint32_t)); // read number of rows
@ -83,18 +83,18 @@ void ArkFile::LoadFile(const char* fileName,
}
in_file.close();
} else {
throw std::runtime_error(std::string("Failed to open %s for reading in LoadFile()!\n") + fileName);
throw std::runtime_error(std::string("Failed to open %s for reading in load_file()!\n") + fileName);
}
*ptrNumBytesPerElement = sizeof(float);
}
void ArkFile::SaveFile(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) {
void ArkFile::save_file(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) {
std::ios_base::openmode mode = std::ios::binary;
if (shouldAppend) {
mode |= std::ios::app;
@ -111,14 +111,14 @@ void ArkFile::SaveFile(const char* fileName,
out_file.write(reinterpret_cast<char*>(ptrMemory), numRows * numColumns * sizeof(float));
out_file.close();
} else {
throw std::runtime_error(std::string("Failed to open %s for writing in SaveFile()!\n") + fileName);
throw std::runtime_error(std::string("Failed to open %s for writing in save_file()!\n") + fileName);
}
}
void NumpyFile::GetFileInfo(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) {
void NumpyFile::get_file_info(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) {
uint32_t numArrays = 0;
uint32_t numMemoryBytes = 0;
@ -135,17 +135,17 @@ void NumpyFile::GetFileInfo(const char* fileName,
if (ptrNumMemoryBytes != NULL)
*ptrNumMemoryBytes = numMemoryBytes;
} else {
throw std::runtime_error(std::string("Failed to get info %s GetFileInfo()!\n") + fileName);
throw std::runtime_error(std::string("Failed to get info %s get_file_info()!\n") + fileName);
}
}
void NumpyFile::LoadFile(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) {
void NumpyFile::load_file(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) {
cnpy::npz_t my_npz1 = cnpy::npz_load(fileName);
auto it = my_npz1.begin();
std::advance(it, arrayIndex);
@ -161,16 +161,16 @@ void NumpyFile::LoadFile(const char* fileName,
*ptrNumBytesPerElement = sizeof(float);
} else {
throw std::runtime_error(std::string("Failed to open %s for reading in LoadFile()!\n") + fileName);
throw std::runtime_error(std::string("Failed to open %s for reading in load_file()!\n") + fileName);
}
}
void NumpyFile::SaveFile(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) {
void NumpyFile::save_file(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) {
std::string mode;
shouldAppend ? mode = "a" : mode = "w";
std::vector<size_t> shape{numRows, numColumns};

View File

@ -11,25 +11,25 @@
/// @brief Interface to work with files like input and output
class BaseFile {
public:
virtual void LoadFile(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) = 0;
virtual void load_file(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) = 0;
virtual void SaveFile(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) = 0;
virtual void save_file(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) = 0;
virtual void GetFileInfo(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) = 0;
virtual void get_file_info(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) = 0;
};
/// @brief Responsible to work with .ark files
@ -43,10 +43,10 @@ public:
* @param ptrNumMemoryBytes pointer to specific number of memory bytes
* @return none.
*/
void GetFileInfo(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) override;
void get_file_info(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) override;
/**
* @brief Load Kaldi ARK speech feature vector file
@ -59,13 +59,13 @@ public:
* @param ptrNumBytesPerElement pointer to number bytes per element (size of float by default)
* @return none.
*/
void LoadFile(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) override;
void load_file(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) override;
/**
* @brief Save Kaldi ARK speech feature vector file
@ -77,12 +77,12 @@ public:
* @param numColumns number of columns
* @return none.
*/
void SaveFile(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) override;
void save_file(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) override;
};
/// @brief Responsible to work with .npz files
@ -96,10 +96,10 @@ public:
* @param ptrNumMemoryBytes pointer to specific number of memory bytes
* @return none.
*/
void GetFileInfo(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) override;
void get_file_info(const char* fileName,
uint32_t numArrayToFindSize,
uint32_t* ptrNumArrays,
uint32_t* ptrNumMemoryBytes) override;
/**
* @brief Load Numpy* uncompressed NPZ speech feature vector file
@ -112,13 +112,13 @@ public:
* @param ptrNumBytesPerElement pointer to number bytes per element (size of float by default)
* @return none.
*/
void LoadFile(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) override;
void load_file(const char* fileName,
uint32_t arrayIndex,
std::string& ptrName,
std::vector<uint8_t>& memory,
uint32_t* ptrNumRows,
uint32_t* ptrNumColumns,
uint32_t* ptrNumBytesPerElement) override;
/**
* @brief Save Numpy* uncompressed NPZ speech feature vector file
@ -130,10 +130,10 @@ public:
* @param numColumns number of columns
* @return none.
*/
void SaveFile(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) override;
void save_file(const char* fileName,
bool shouldAppend,
std::string name,
void* ptrMemory,
uint32_t numRows,
uint32_t numColumns) override;
};

View File

@ -67,7 +67,7 @@ int main(int argc, char* argv[]) {
while (getline(stream, outStr, ',')) {
std::string filename(fileNameNoExt(outStr) + "." + extInputFile);
inputFiles.push_back(filename);
file->GetFileInfo(filename.c_str(), 0, &currentNumUtterances, &currentNumBytesThisUtterance);
file->get_file_info(filename.c_str(), 0, &currentNumUtterances, &currentNumBytesThisUtterance);
if (numUtterances == 0) {
numUtterances = currentNumUtterances;
} else if (currentNumUtterances != numUtterances) {
@ -84,7 +84,7 @@ int main(int argc, char* argv[]) {
ov::runtime::Core core;
slog::info << "Loading model files:" << slog::endl << FLAGS_m << slog::endl;
std::shared_ptr<ov::Model> model = core.read_model(FLAGS_m);
CheckNumberOfInputs(model->inputs().size(), numInputFiles);
check_number_of_inputs(model->inputs().size(), numInputFiles);
const ov::Layout tensor_layout{"NC"};
ov::preprocess::PrePostProcessor proc(model);
for (int i = 0; i < model->inputs().size(); i++) {
@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {
if (!FLAGS_rg.empty()) {
slog::warn << "Custom scale factor will be used for imported gna model: " << FLAGS_rg << slog::endl;
}
auto scaleFactorInput = ParseScaleFactors(FLAGS_sf);
auto scaleFactorInput = parse_scale_factors(FLAGS_sf);
if (numInputFiles != scaleFactorInput.size()) {
std::string errMessage(
"Incorrect command line for multiple inputs: " + std::to_string(scaleFactorInput.size()) +
@ -144,17 +144,18 @@ int main(int argc, char* argv[]) {
std::string name;
std::vector<uint8_t> ptrFeatures;
uint32_t numArrays(0), numBytes(0), numFrames(0), numFrameElements(0), numBytesPerElement(0);
file->GetFileInfo(inputFileName, 0, &numArrays, &numBytes);
file->get_file_info(inputFileName, 0, &numArrays, &numBytes);
ptrFeatures.resize(numBytes);
file->LoadFile(inputFileName,
0,
name,
ptrFeatures,
&numFrames,
&numFrameElements,
&numBytesPerElement);
auto floatScaleFactor =
ScaleFactorForQuantization(ptrFeatures.data(), MAX_VAL_2B_FEAT, numFrames * numFrameElements);
file->load_file(inputFileName,
0,
name,
ptrFeatures,
&numFrames,
&numFrameElements,
&numBytesPerElement);
auto floatScaleFactor = scale_factor_for_quantization(ptrFeatures.data(),
MAX_VAL_2B_FEAT,
numFrames * numFrameElements);
slog::info << "Using scale factor of " << floatScaleFactor << " calculated from first utterance."
<< slog::endl;
std::string scaleFactorConfigKey =
@ -188,7 +189,7 @@ int main(int argc, char* argv[]) {
auto t0 = Time::now();
std::vector<std::string> outputs;
if (!FLAGS_oname.empty()) {
std::vector<std::string> output_names = ConvertStrToVector(FLAGS_oname);
std::vector<std::string> output_names = convert_str_to_vector(FLAGS_oname);
std::vector<size_t> ports;
for (const auto& outBlobName : output_names) {
int pos_layer = outBlobName.rfind(":");
@ -246,9 +247,9 @@ int main(int argc, char* argv[]) {
// --------------------------------------------------
std::vector<ov::runtime::Tensor> ptrInputBlobs;
auto cInputInfo = executableNet.inputs();
CheckNumberOfInputs(cInputInfo.size(), numInputFiles);
check_number_of_inputs(cInputInfo.size(), numInputFiles);
if (!FLAGS_iname.empty()) {
std::vector<std::string> inputNameBlobs = ConvertStrToVector(FLAGS_iname);
std::vector<std::string> inputNameBlobs = convert_str_to_vector(FLAGS_iname);
if (inputNameBlobs.size() != cInputInfo.size()) {
std::string errMessage(std::string("Number of network inputs ( ") + std::to_string(cInputInfo.size()) +
" ) is not equal to the number of inputs entered in the -iname argument ( " +
@ -272,14 +273,14 @@ int main(int argc, char* argv[]) {
std::vector<std::string> reference_name_files;
size_t count_file = 1;
if (!FLAGS_o.empty()) {
output_name_files = ConvertStrToVector(FLAGS_o);
output_name_files = convert_str_to_vector(FLAGS_o);
if (output_name_files.size() != outputs.size() && !outputs.empty()) {
throw std::logic_error("The number of output files is not equal to the number of network outputs.");
}
count_file = output_name_files.empty() ? 1 : output_name_files.size();
}
if (!FLAGS_r.empty()) {
reference_name_files = ConvertStrToVector(FLAGS_r);
reference_name_files = convert_str_to_vector(FLAGS_r);
if (reference_name_files.size() != outputs.size() && !outputs.empty()) {
throw std::logic_error("The number of reference files is not equal to the number of network outputs.");
}
@ -291,7 +292,7 @@ int main(int argc, char* argv[]) {
std::vector<std::vector<uint8_t>> ptrUtterances;
std::vector<uint8_t> ptrScores;
std::vector<uint8_t> ptrReferenceScores;
score_error_t frameError, totalError;
ScoreErrorT frameError, totalError;
ptrUtterances.resize(inputFiles.size());
// initialize memory state before starting
for (auto&& state : inferRequests.begin()->inferRequest.query_state()) {
@ -316,15 +317,15 @@ int main(int argc, char* argv[]) {
std::vector<uint8_t> ptrUtterance;
auto inputFilename = inputFiles[i].c_str();
uint32_t currentNumFrames(0), currentNumFrameElementsInput(0), currentNumBytesPerElementInput(0);
file->GetFileInfo(inputFilename, utteranceIndex, &n, &numBytesThisUtterance[i]);
file->get_file_info(inputFilename, utteranceIndex, &n, &numBytesThisUtterance[i]);
ptrUtterance.resize(numBytesThisUtterance[i]);
file->LoadFile(inputFilename,
utteranceIndex,
uttName,
ptrUtterance,
&currentNumFrames,
&currentNumFrameElementsInput,
&currentNumBytesPerElementInput);
file->load_file(inputFilename,
utteranceIndex,
uttName,
ptrUtterance,
&currentNumFrames,
&currentNumFrameElementsInput,
&currentNumBytesPerElementInput);
if (numFrames == 0) {
numFrames = currentNumFrames;
} else if (numFrames != currentNumFrames) {
@ -356,22 +357,22 @@ int main(int argc, char* argv[]) {
throw std::logic_error("Invalid Reference Scores file");
}
std::string refUtteranceName;
fileReferenceScores->GetFileInfo(reference_name_files[next_output].c_str(),
utteranceIndex,
&n,
&numBytesReferenceScoreThisUtterance);
fileReferenceScores->get_file_info(reference_name_files[next_output].c_str(),
utteranceIndex,
&n,
&numBytesReferenceScoreThisUtterance);
ptrReferenceScores.resize(numBytesReferenceScoreThisUtterance);
fileReferenceScores->LoadFile(reference_name_files[next_output].c_str(),
utteranceIndex,
refUtteranceName,
ptrReferenceScores,
&numFramesReference,
&numFrameElementsReference,
&numBytesPerElementReference);
fileReferenceScores->load_file(reference_name_files[next_output].c_str(),
utteranceIndex,
refUtteranceName,
ptrReferenceScores,
&numFramesReference,
&numFrameElementsReference,
&numBytesPerElementReference);
}
double totalTime = 0.0;
std::cout << "Utterance " << utteranceIndex << ": " << std::endl;
ClearScoreError(&totalError);
clear_score_error(&totalError);
totalError.threshold = frameError.threshold = MAX_SCORE_DIFFERENCE;
auto outputFrame = &ptrScores.front();
std::vector<uint8_t*> inputFrame;
@ -428,20 +429,20 @@ int main(int argc, char* argv[]) {
if (!FLAGS_oname.empty())
outputBlob =
inferRequest.inferRequest.get_tensor(executableNet.outputs().back());
CompareScores(
compare_scores(
outputBlob.data<float>(),
&ptrReferenceScores[inferRequest.frameIndex * numFrameElementsReference *
numBytesPerElementReference],
&frameError,
inferRequest.numFramesThisBatch,
numFrameElementsReference);
UpdateScoreError(&frameError, &totalError);
update_score_error(&frameError, &totalError);
}
if (FLAGS_pc) {
// retrieve new counters
getPerformanceCounters(inferRequest.inferRequest, callPerfMap);
get_performance_counters(inferRequest.inferRequest, callPerfMap);
// summarize retrieved counters with all previous
sumPerformanceCounters(callPerfMap, utterancePerfMap, totalNumberOfRunsOnHw);
sum_performance_counters(callPerfMap, utterancePerfMap, totalNumberOfRunsOnHw);
}
}
// -----------------------------------------------------------------------------------------------------
@ -510,12 +511,12 @@ int main(int argc, char* argv[]) {
}
/* Save output data to file */
bool shouldAppend = (utteranceIndex == 0) ? false : true;
fileOutput->SaveFile(output_name_files[next_output].c_str(),
shouldAppend,
uttName,
&ptrScores.front(),
numFramesFile,
numScoresPerFrame);
fileOutput->save_file(output_name_files[next_output].c_str(),
shouldAppend,
uttName,
&ptrScores.front(),
numFramesFile,
numScoresPerFrame);
}
/** Show performance results **/
std::cout << "Total time in Infer (HW and SW):\t" << totalTime << " ms" << std::endl;
@ -524,16 +525,16 @@ int main(int argc, char* argv[]) {
<< std::endl;
if (FLAGS_pc) {
// print performance results
printPerformanceCounters(utterancePerfMap,
frameIndex,
std::cout,
getFullDeviceName(core, FLAGS_d),
totalNumberOfRunsOnHw,
FLAGS_d);
print_performance_counters(utterancePerfMap,
frameIndex,
std::cout,
getFullDeviceName(core, FLAGS_d),
totalNumberOfRunsOnHw,
FLAGS_d);
}
if (!FLAGS_r.empty()) {
// print statistical score error
printReferenceCompareResults(totalError, numFrames, std::cout);
print_reference_compare_results(totalError, numFrames, std::cout);
}
std::cout << "End of Utterance " << utteranceIndex << std::endl << std::endl;
// -----------------------------------------------------------------------------------------------------

View File

@ -17,7 +17,7 @@ typedef std::chrono::duration<float> fsec;
/**
* @brief struct to store score error
*/
typedef struct {
struct ScoreErrorT {
uint32_t numScores;
uint32_t numErrors;
float threshold;
@ -29,7 +29,7 @@ typedef struct {
float maxRelError;
float sumRelError;
float sumSquaredRelError;
} score_error_t;
};
/**
* @brief struct to store infer request data per frame
@ -46,7 +46,7 @@ struct InferRequestStruct {
* @param numInputFiles number of input files
* @return none.
*/
void CheckNumberOfInputs(size_t numInputs, size_t numInputFiles) {
void check_number_of_inputs(size_t numInputs, size_t numInputFiles) {
if (numInputs != numInputFiles) {
throw std::logic_error("Number of network inputs (" + std::to_string(numInputs) +
")"
@ -62,7 +62,7 @@ void CheckNumberOfInputs(size_t numInputs, size_t numInputFiles) {
* @param numElements number of elements in speech feature vector
* @return scale factor
*/
float ScaleFactorForQuantization(void* ptrFloatMemory, float targetMax, uint32_t numElements) {
float scale_factor_for_quantization(void* ptrFloatMemory, float targetMax, uint32_t numElements) {
float* ptrFloatFeat = reinterpret_cast<float*>(ptrFloatMemory);
float max = 0.0;
float scaleFactor;
@ -87,7 +87,7 @@ float ScaleFactorForQuantization(void* ptrFloatMemory, float targetMax, uint32_t
* @param error pointer to score error struct
* @return none.
*/
void ClearScoreError(score_error_t* error) {
void clear_score_error(ScoreErrorT* error) {
error->numScores = 0;
error->numErrors = 0;
error->maxError = 0.0;
@ -106,7 +106,7 @@ void ClearScoreError(score_error_t* error) {
* @param totalError pointer to total score error struct
* @return none.
*/
void UpdateScoreError(score_error_t* error, score_error_t* totalError) {
void update_score_error(ScoreErrorT* error, ScoreErrorT* totalError) {
totalError->numErrors += error->numErrors;
totalError->numScores += error->numScores;
totalError->sumRmsError += error->rmsError;
@ -131,14 +131,14 @@ void UpdateScoreError(score_error_t* error, score_error_t* totalError) {
* @param numColumns - number columns in score error arrays
* @return none.
*/
void CompareScores(float* ptrScoreArray,
void* ptrRefScoreArray,
score_error_t* scoreError,
uint32_t numRows,
uint32_t numColumns) {
void compare_scores(float* ptrScoreArray,
void* ptrRefScoreArray,
ScoreErrorT* scoreError,
uint32_t numRows,
uint32_t numColumns) {
uint32_t numErrors = 0;
ClearScoreError(scoreError);
clear_score_error(scoreError);
float* A = ptrScoreArray;
float* B = reinterpret_cast<float*>(ptrRefScoreArray);
@ -178,7 +178,7 @@ void CompareScores(float* ptrScoreArray,
* @param error pointer to score error struct
* @return error
*/
float StdDevError(score_error_t error) {
float std_dev_error(ScoreErrorT error) {
return (sqrt(error.sumSquaredError / error.numScores -
(error.sumError / error.numScores) * (error.sumError / error.numScores)));
}
@ -211,7 +211,7 @@ inline void native_cpuid(unsigned int* eax, unsigned int* ebx, unsigned int* ecx
* @brief Get GNA module frequency
* @return GNA module frequency in MHz
*/
float getGnaFrequencyMHz() {
float get_gna_frequency_mHz() {
uint32_t eax = 1;
uint32_t ebx = 0;
uint32_t ecx = 0;
@ -264,11 +264,11 @@ float getGnaFrequencyMHz() {
* @param stream output stream
* @return none.
*/
void printReferenceCompareResults(score_error_t const& totalError, size_t framesNum, std::ostream& stream) {
void print_reference_compare_results(ScoreErrorT const& totalError, size_t framesNum, std::ostream& stream) {
stream << " max error: " << totalError.maxError << std::endl;
stream << " avg error: " << totalError.sumError / totalError.numScores << std::endl;
stream << " avg rms error: " << totalError.sumRmsError / framesNum << std::endl;
stream << " stdev error: " << StdDevError(totalError) << std::endl << std::endl;
stream << " stdev error: " << std_dev_error(totalError) << std::endl << std::endl;
stream << std::endl;
}
@ -282,12 +282,12 @@ void printReferenceCompareResults(score_error_t const& totalError, size_t frames
* @param FLAGS_d flag of device
* @return none.
*/
void printPerformanceCounters(std::map<std::string, ov::runtime::ProfilingInfo> const& utterancePerfMap,
size_t numberOfFrames,
std::ostream& stream,
std::string fullDeviceName,
const uint64_t numberOfFramesOnHw,
std::string FLAGS_d) {
void print_performance_counters(std::map<std::string, ov::runtime::ProfilingInfo> const& utterancePerfMap,
size_t numberOfFrames,
std::ostream& stream,
std::string fullDeviceName,
const uint64_t numberOfFramesOnHw,
std::string FLAGS_d) {
#if !defined(__arm__) && !defined(_M_ARM) && !defined(__aarch64__) && !defined(_M_ARM64)
stream << std::endl << "Performance counts:" << std::endl;
stream << std::setw(10) << std::right << ""
@ -301,7 +301,7 @@ void printPerformanceCounters(std::map<std::string, ov::runtime::ProfilingInfo>
stream << std::endl;
// if GNA HW counters
// get frequency of GNA module
float freq = getGnaFrequencyMHz();
float freq = get_gna_frequency_mHz();
for (const auto& it : utterancePerfMap) {
std::string const& counter_name = it.first;
float current_units_us = static_cast<float>(it.second.real_time.count()) / freq;
@ -331,8 +331,8 @@ void printPerformanceCounters(std::map<std::string, ov::runtime::ProfilingInfo>
* @param perfCounters reference to a map to save performance counters
* @return none.
*/
void getPerformanceCounters(ov::runtime::InferRequest& request,
std::map<std::string, ov::runtime::ProfilingInfo>& perfCounters) {
void get_performance_counters(ov::runtime::InferRequest& request,
std::map<std::string, ov::runtime::ProfilingInfo>& perfCounters) {
auto retPerfCounters = request.get_profiling_info();
for (const auto& element : retPerfCounters) {
@ -347,9 +347,9 @@ void getPerformanceCounters(ov::runtime::InferRequest& request,
* @param totalRunsOnHw reference to a total number of frames computed on GNA HW
* @return none.
*/
void sumPerformanceCounters(std::map<std::string, ov::runtime::ProfilingInfo> const& perfCounters,
std::map<std::string, ov::runtime::ProfilingInfo>& totalPerfCounters,
uint64_t& totalRunsOnHw) {
void sum_performance_counters(std::map<std::string, ov::runtime::ProfilingInfo> const& perfCounters,
std::map<std::string, ov::runtime::ProfilingInfo>& totalPerfCounters,
uint64_t& totalRunsOnHw) {
auto runOnHw = false;
for (const auto& pair : perfCounters) {
totalPerfCounters[pair.first].real_time += pair.second.real_time;
@ -364,7 +364,7 @@ void sumPerformanceCounters(std::map<std::string, ov::runtime::ProfilingInfo> co
* @param str reference to user-specified input scale factor for quantization, can be separated by comma
* @return vector scale factors
*/
std::vector<std::string> ParseScaleFactors(const std::string& str) {
std::vector<std::string> parse_scale_factors(const std::string& str) {
std::vector<std::string> scaleFactorInput;
if (!str.empty()) {
@ -391,7 +391,7 @@ std::vector<std::string> ParseScaleFactors(const std::string& str) {
* @param str file names separated by comma
* @return vector of file names
*/
std::vector<std::string> ConvertStrToVector(std::string str) {
std::vector<std::string> convert_str_to_vector(std::string str) {
std::vector<std::string> blobName;
if (!str.empty()) {
size_t pos_last = 0;