Files
openvino/samples/cpp/benchmark_app/statistics_report.hpp

158 lines
4.9 KiB
C++
Raw Normal View History

// Copyright (C) 2018-2022 Intel Corporation
2019-04-12 18:25:53 +03:00
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <map>
#include <string>
#include <utility>
#include <vector>
2019-04-12 18:25:53 +03:00
#ifdef JSON_HEADER
# include <json.hpp>
#else
# include <nlohmann/json.hpp>
#endif
// clang-format off
#include "samples/common.hpp"
#include "samples/csv_dumper.hpp"
#include "samples/slog.hpp"
Add benchmark samples (#13388) * Add sync_bnehcmark * Fix Unix comilation * niter->time * Explain main loop * samples: factor out common * Code style * clang-format -i * return 0; -> return EXIT_SUCCESS;, +x * Update throughput_benchmark * Add READMEs * Fix READMEs refs * Add sync_benchmark.py * Add niter, infer_new_request, -pc * from datetime import timedelta * Fix niter and seconds_to_run * Add disclaimer about benchmark_app performance * Update samples/cpp/benchmark/sync_benchmark/README.md * Add dynamic_shape_bert_benhcmark * Add dynamic_shape_detection_benchmark * Adopt for detr-resnet50 * Remove sync_benchmark2, throughput_benchmark2, perf counters * clang-format -i * Fix flake8 * Add README.md * Add links to sample_dynamic_shape_bert_benchmark * Add softmax * nameless LatencyMetrics * parent.parent -> parents[2] * Add bert_benhcmark sample * Code style * Add bert_benhcmark/README.md * rm -r samples/python/benchmark/dynamic_shape_bert_benhcmark/ * rm -r samples/cpp/benchmark/dynamic_shape_detection_benchmark/ * bert_benhcmark/README.md: remove dynamic shape * Remove add_subdirectory(dynamic_shape_detection_benchmark) * flake8 * samples: Add a note about CUMULATIVE_THROUGHPUT, don’t expect get_property() to throw, don’t introduce json dependency for samples/cpp/common * / namespace * Add article * namespace -> static * Update README, seconds_ro_run 10, niter 10, no inter alinment * percentile->median * benchmark samples: use generate(), align logs, update READMEs * benchmakr samples: remove percentile() * samples/python/benchmark/bert_benhcmark/bert_benhcmark.py: report average sequence length and processing time * Python samples: move requirements.txt to every sample * Remove numpy from requirements.txt * Remove Building section from Python samples, install only required extras from openvino-dev, set up environment for bert_benhcmark, report duration for bert_benhcmark * Install openvino-dev for Hello Reshape SSD C++ Sample
2022-12-05 15:12:53 +04:00
#include "samples/latency_metrics.hpp"
Dynamic reshapes (#7788) * Merged and compiling * Fix for dynamic shape type * review fixes * renamed blob shape to tensor shape, small improvements * fix code style * added parsing of multiple shapes * store latency per group, add isIdleRequestAvailable() to Infer Queue * added cached random inputs * redesign pipeline, added new metrics(avg, max, min), added metrics per groups * fixed code style * small improvements * modified tensor parameters parsing * modified -i parameter parsing: added possibility to specify input names * implemented image cashing * added cashed blobs creating * added -pcseq flag, modified batch filling, changes fps formula * improvements * code formatting * code formatting2 * apply suggestions from review * replaced Buffer class with InferenceEngine Blobs * use batch size in blobs filling * added shared blob allocator to handle blob's data * fixed warnings & code style * allocate blobs * fix for networks with image info input * added comments & fixed codestyle * clear data in free() in SharedBlobAllocator * remove unnecessary check * Delimeter is changed to :: * stylefix * added layout from string function, small improvements * modified parsing to enable : in input parameters * small fixes * small fixes * added missed blob allocation, fixes * [TEST]added support for remote blobs * fix remote blobs * new inputs/files output format * removed vectors resize which caused bugs * made cl::Buffer type under ifdef, fix inputs filling * changed batch() function to not throwing exceptions * removed unused var * fix code style * replace empty name in input files with name from net input * restored old behaviour for static models * fix code style * fix warning - made const iterator * fix warning - remove reference in loop variable * added random and image_info input types to -i, fix problem with layout * replaced batch() with getBatchSize() in main * fix layout, shape, tensor shape parameters parsing * upd help messages for input, tensor shape and pcseq command * added buffer for cl output blobs, small fixes Signed-off-by: ivikhrev <ivan.vikhrev@intel.com> * added legacy mode * restore setBlob * code style formatting * move collecting latency for groups under flag * removed not applicable layouts * added hint to error message when wrong input name in -tensor_shape was specified * added new metrics to statistics report * Apply suggestions from code review * fix binary blobs filling when layout is CN * apply suggestions * moved file in the right place after rebase * improved -pcseq output * updated args and readme * removed TEMPLATE plugin registration * fix -shape arg decsription * enable providing several -i args as input * renamed legacy_mode to inference_only and made it default for static models, renamed tensor_shape to data_shape * upd readme * use getBlob() in inference only mode * fix old input type for static case * fix typo * upd readme * move log about benchmark mode to the measuring perfomance step * added class for latency metrics * upd readme, fix typos, renamed funcs * fix warning and upd parsing to avoid error with : in file paths * fix error on centos : error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&) * added check for key in inputs * renamed input to inputs * adjust batch size for binary blobs * replaced warning with exception in bench mode defining * align measurement cycle with master Co-authored-by: ivikhrev <ivan.vikhrev@intel.com>
2021-12-17 12:20:43 +03:00
#include "utils.hpp"
// clang-format on
2019-04-12 18:25:53 +03:00
// @brief statistics reports types
static constexpr char noCntReport[] = "no_counters";
2019-08-09 19:02:42 +03:00
static constexpr char averageCntReport[] = "average_counters";
2019-04-12 18:25:53 +03:00
static constexpr char detailedCntReport[] = "detailed_counters";
static constexpr char sortDetailedCntReport[] = "sort_detailed_counters";
2019-04-12 18:25:53 +03:00
class StatisticsVariant {
public:
enum Type { INT, DOUBLE, STRING, ULONGLONG, METRICS };
StatisticsVariant(std::string csv_name, std::string json_name, int v)
: csv_name(csv_name),
json_name(json_name),
i_val(v),
type(INT) {}
StatisticsVariant(std::string csv_name, std::string json_name, double v)
: csv_name(csv_name),
json_name(json_name),
d_val(v),
type(DOUBLE) {}
StatisticsVariant(std::string csv_name, std::string json_name, const std::string& v)
: csv_name(csv_name),
json_name(json_name),
s_val(v),
type(STRING) {}
StatisticsVariant(std::string csv_name, std::string json_name, unsigned long long v)
: csv_name(csv_name),
json_name(json_name),
ull_val(v),
type(ULONGLONG) {}
StatisticsVariant(std::string csv_name, std::string json_name, uint32_t v)
: csv_name(csv_name),
json_name(json_name),
ull_val(v),
type(ULONGLONG) {}
StatisticsVariant(std::string csv_name, std::string json_name, unsigned long v)
: csv_name(csv_name),
json_name(json_name),
ull_val(v),
type(ULONGLONG) {}
StatisticsVariant(std::string csv_name, std::string json_name, const LatencyMetrics& v)
: csv_name(csv_name),
json_name(json_name),
metrics_val(v),
type(METRICS) {}
~StatisticsVariant() {}
std::string csv_name;
std::string json_name;
int i_val = 0;
double d_val = 0;
unsigned long long ull_val = 0;
std::string s_val;
LatencyMetrics metrics_val;
Type type;
std::string to_string() const;
void write_to_json(nlohmann::json& js) const;
Dynamic reshapes (#7788) * Merged and compiling * Fix for dynamic shape type * review fixes * renamed blob shape to tensor shape, small improvements * fix code style * added parsing of multiple shapes * store latency per group, add isIdleRequestAvailable() to Infer Queue * added cached random inputs * redesign pipeline, added new metrics(avg, max, min), added metrics per groups * fixed code style * small improvements * modified tensor parameters parsing * modified -i parameter parsing: added possibility to specify input names * implemented image cashing * added cashed blobs creating * added -pcseq flag, modified batch filling, changes fps formula * improvements * code formatting * code formatting2 * apply suggestions from review * replaced Buffer class with InferenceEngine Blobs * use batch size in blobs filling * added shared blob allocator to handle blob's data * fixed warnings & code style * allocate blobs * fix for networks with image info input * added comments & fixed codestyle * clear data in free() in SharedBlobAllocator * remove unnecessary check * Delimeter is changed to :: * stylefix * added layout from string function, small improvements * modified parsing to enable : in input parameters * small fixes * small fixes * added missed blob allocation, fixes * [TEST]added support for remote blobs * fix remote blobs * new inputs/files output format * removed vectors resize which caused bugs * made cl::Buffer type under ifdef, fix inputs filling * changed batch() function to not throwing exceptions * removed unused var * fix code style * replace empty name in input files with name from net input * restored old behaviour for static models * fix code style * fix warning - made const iterator * fix warning - remove reference in loop variable * added random and image_info input types to -i, fix problem with layout * replaced batch() with getBatchSize() in main * fix layout, shape, tensor shape parameters parsing * upd help messages for input, tensor shape and pcseq command * added buffer for cl output blobs, small fixes Signed-off-by: ivikhrev <ivan.vikhrev@intel.com> * added legacy mode * restore setBlob * code style formatting * move collecting latency for groups under flag * removed not applicable layouts * added hint to error message when wrong input name in -tensor_shape was specified * added new metrics to statistics report * Apply suggestions from code review * fix binary blobs filling when layout is CN * apply suggestions * moved file in the right place after rebase * improved -pcseq output * updated args and readme * removed TEMPLATE plugin registration * fix -shape arg decsription * enable providing several -i args as input * renamed legacy_mode to inference_only and made it default for static models, renamed tensor_shape to data_shape * upd readme * use getBlob() in inference only mode * fix old input type for static case * fix typo * upd readme * move log about benchmark mode to the measuring perfomance step * added class for latency metrics * upd readme, fix typos, renamed funcs * fix warning and upd parsing to avoid error with : in file paths * fix error on centos : error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&) * added check for key in inputs * renamed input to inputs * adjust batch size for binary blobs * replaced warning with exception in bench mode defining * align measurement cycle with master Co-authored-by: ivikhrev <ivan.vikhrev@intel.com>
2021-12-17 12:20:43 +03:00
};
2019-04-12 18:25:53 +03:00
/// @brief Responsible for collecting of statistics and dumping to .csv file
class StatisticsReport {
public:
typedef std::vector<ov::ProfilingInfo> PerformanceCounters;
typedef std::vector<StatisticsVariant> Parameters;
2019-10-04 19:26:43 +03:00
2019-04-12 18:25:53 +03:00
struct Config {
std::string report_type;
std::string report_folder;
};
enum class Category { COMMAND_LINE_PARAMETERS, RUNTIME_CONFIG, EXECUTION_RESULTS, EXECUTION_RESULTS_GROUPPED };
2019-10-04 19:26:43 +03:00
explicit StatisticsReport(Config config) : _config(std::move(config)) {
2019-10-04 19:26:43 +03:00
_separator =
#if defined _WIN32 || defined __CYGWIN__
# if defined UNICODE
L"\\";
# else
"\\";
# endif
2019-10-04 19:26:43 +03:00
#else
"/";
2019-10-04 19:26:43 +03:00
#endif
if (_config.report_folder.empty())
_separator = "";
2019-04-12 18:25:53 +03:00
}
void add_parameters(const Category& category, const Parameters& parameters);
2019-04-12 18:25:53 +03:00
virtual void dump();
2019-04-12 18:25:53 +03:00
virtual void dump_performance_counters(const std::vector<PerformanceCounters>& perfCounts);
2019-04-12 18:25:53 +03:00
private:
void dump_performance_counters_request(CsvDumper& dumper, const PerformanceCounters& perfCounts);
void dump_sort_performance_counters_request(CsvDumper& dumper, const PerformanceCounters& perfCounts);
static bool sort_profiling_descend(const ov::ProfilingInfo& profiling1, const ov::ProfilingInfo& profiling2) {
return profiling1.real_time > profiling2.real_time;
}
2019-04-12 18:25:53 +03:00
protected:
2019-04-12 18:25:53 +03:00
// configuration of current benchmark execution
const Config _config;
2019-10-04 19:26:43 +03:00
// parameters
std::map<Category, Parameters> _parameters;
// csv separator
std::string _separator;
StatisticsReport::PerformanceCounters get_average_performance_counters(
const std::vector<PerformanceCounters>& perfCounts);
};
class StatisticsReportJSON : public StatisticsReport {
public:
explicit StatisticsReportJSON(Config config) : StatisticsReport(std::move(config)) {}
void dump() override;
void dump_performance_counters(const std::vector<PerformanceCounters>& perfCounts) override;
private:
void dump_parameters(nlohmann::json& js, const StatisticsReport::Parameters& parameters);
const nlohmann::json perf_counters_to_json(const StatisticsReport::PerformanceCounters& perfCounts);
const nlohmann::json sort_perf_counters_to_json(const StatisticsReport::PerformanceCounters& perfCounts);
static bool sort_profiling_descend(const ov::ProfilingInfo& profiling1, const ov::ProfilingInfo& profiling2) {
return profiling1.real_time > profiling2.real_time;
}
2019-04-12 18:25:53 +03:00
};