// Copyright (C) 2018-2025 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // #pragma once #include #include #include #include #include #include #include #include #ifdef USE_OPENCV const std::unordered_set supported_image_extensions = {"bmp", "dib", "jpeg", "jpg", "jpe", "jp2", "png", "pbm", "pgm", "ppm", "sr", "ras", "tiff", "tif"}; #else const std::unordered_set supported_image_extensions = {"bmp"}; #endif const std::unordered_set supported_numpy_extensions = {"npy"}; const std::unordered_set supported_binary_extensions = {"bin"}; typedef std::chrono::high_resolution_clock Time; typedef std::chrono::nanoseconds ns; inline uint64_t get_duration_in_milliseconds(uint64_t duration) { return duration * 1000LL; } inline uint64_t get_duration_in_nanoseconds(uint64_t duration) { return duration * 1000000000LL; } inline double get_duration_ms_till_now(Time::time_point& startTime) { return std::chrono::duration_cast(Time::now() - startTime).count() * 0.000001; }; namespace benchmark_app { struct InputInfo { ov::element::Type type; ov::PartialShape partialShape; ov::Shape dataShape; ov::Layout layout; std::vector scale; std::vector mean; bool is_image() const; bool is_image_info() const; size_t width() const; size_t height() const; size_t channels() const; size_t batch() const; size_t depth() const; std::vector fileNames; }; using InputsInfo = std::map; using PartialShapes = std::map; } // namespace benchmark_app bool can_measure_as_static(const std::vector& app_input_info); bool is_virtual_device(const std::string& device_name); bool is_virtual_device_found(const std::vector& device_names); void update_device_properties_setting(const std::string& device_name, ov::AnyMap& config, std::pair device_property); std::vector parse_devices(const std::string& device_string); uint32_t device_default_device_duration_in_seconds(const std::string& device); std::map parse_value_per_device(const std::vector& devices, const std::string& values_string); void parse_value_for_virtual_device(const std::string& device, std::map& values_string); template void update_device_config_for_virtual_device(const std::string& value, ov::AnyMap& device_config, ov::Property property); std::string get_shapes_string(const benchmark_app::PartialShapes& shapes); size_t get_batch_size(const benchmark_app::InputsInfo& inputs_info); std::vector split(const std::string& s, char delim); std::map> parse_scale_or_mean(const std::string& scale_mean, const benchmark_app::InputsInfo& inputs_info); std::pair> parse_input_files(const std::string& file_paths_string); std::map> parse_input_arguments(const std::vector& args); std::map> parse_input_parameters(const std::string& parameter_string, const ov::ParameterVector& input_info); /// /// Parses command line data and data obtained from the function and returns configuration of each input /// /// command-line shape string /// command-line layout string /// command-line batch string /// command-line data_shape string /// command-line iscale string /// command-line imean string /// inputs vector obtained from ov::Model /// returns true to this parameter if reshape is required /// vector of benchmark_app::InputsInfo elements. /// Each element is a configuration item for every test configuration case /// (number of cases is calculated basing on data_shape and other parameters). /// Each element is a map (input_name, configuration) containing data for each input std::vector get_inputs_info(const std::string& shape_string, const std::string& layout_string, const size_t batch_size, const std::string& data_shapes_string, const std::map>& fileNames, const std::string& scale_string, const std::string& mean_string, const std::vector>& input_info, bool& reshape_required); /// /// Parses command line data and data obtained from the function and returns configuration of each input /// /// command-line shape string /// command-line layout string /// command-line batch string /// command-line data_shape string /// command-line iscale string /// command-line imean string /// inputs vector obtained from ov::Model /// returns true to this parameter if reshape is required /// vector of benchmark_app::InputsInfo elements. /// Each element is a configuration item for every test configuration case /// (number of cases is calculated basing on data_shape and other parameters). /// Each element is a map (input_name, configuration) containing data for each /// input std::vector get_inputs_info(const std::string& shape_string, const std::string& layout_string, const size_t batch_size, const std::string& data_shapes_string, const std::map>& fileNames, const std::string& scale_string, const std::string& mean_string, const std::vector>& input_info); void dump_config(const std::string& filename, const std::map& config); void load_config(const std::string& filename, std::map& config); std::string get_extension(const std::string& name); bool is_binary_file(const std::string& filePath); bool is_numpy_file(const std::string& filePath); bool is_image_file(const std::string& filePath); bool contains_binaries(const std::vector& filePaths); std::vector filter_files_by_extensions(const std::vector& filePaths, const std::unordered_set& extensions); std::string parameter_name_to_tensor_name( const std::string& name, const std::vector>& inputs_info, const std::vector>& outputs_info = std::vector>()); template void convert_io_names_in_map( T& map, const std::vector>& inputs_info, const std::vector>& outputs_info = std::vector>()) { T new_map; for (auto& item : map) { new_map[item.first == "" ? "" : parameter_name_to_tensor_name(item.first, inputs_info, outputs_info)] = std::move(item.second); } map = new_map; }