From c96294600e933e1ec08c8b2ece5196dd13bf9c73 Mon Sep 17 00:00:00 2001 From: Maciej Falkowski Date: Mon, 3 Apr 2023 15:25:48 +0200 Subject: [PATCH] Add param to execute infer requests at a fixed frequency Signed-off-by: Maciej Falkowski Signed-off-by: Ooi, Boon Sin --- samples/cpp/benchmark_app/benchmark_app.hpp | 9 +++++++++ samples/cpp/benchmark_app/main.cpp | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/samples/cpp/benchmark_app/benchmark_app.hpp b/samples/cpp/benchmark_app/benchmark_app.hpp index 99cbd7edff8856..c8411855e38022 100644 --- a/samples/cpp/benchmark_app/benchmark_app.hpp +++ b/samples/cpp/benchmark_app/benchmark_app.hpp @@ -65,6 +65,11 @@ static const char cache_dir_message[] = "Optional. Enables caching of loaded mod static const char load_from_file_message[] = "Optional. Loads model from file directly without read_model." " All CNNNetwork options (like re-shape) will be ignored"; +/// @brief message for run frequency +static const char run_frequency_message[] = + "Execute at a fixed frequency. Note if the targeted rate per second cannot be reached, " + "the benchmark would start the next run immediately, trying its best to catch up."; + /// @brief message for execution time static const char execution_time_message[] = "Optional. Time in seconds to execute topology."; @@ -307,6 +312,9 @@ DEFINE_string(api, "async", api_message); /// @brief Number of infer requests in parallel DEFINE_uint64(nireq, 0, infer_requests_count_message); +/// @brief Execute infer requests at a fixed frequency +DEFINE_double(rfreq, 0, run_frequency_message); + /// @brief Number of streams to use for inference on the CPU (also affects Hetero cases) DEFINE_string(nstreams, "", infer_num_streams_message); @@ -388,6 +396,7 @@ static void show_usage() { std::cout << " -hint (latency or throughput or cumulative_throughput or none) " << hint_message << std::endl; std::cout << " -niter " << iterations_count_message << std::endl; + std::cout << " -rfreq \"\" " << run_frequency_message << std::endl; std::cout << " -t " << execution_time_message << std::endl; std::cout << std::endl; std::cout << "Input shapes" << std::endl; diff --git a/samples/cpp/benchmark_app/main.cpp b/samples/cpp/benchmark_app/main.cpp index 2cfd15b77afb6e..f026597d82c182 100644 --- a/samples/cpp/benchmark_app/main.cpp +++ b/samples/cpp/benchmark_app/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include // clang-format off #include "openvino/openvino.hpp" @@ -1153,6 +1154,11 @@ int main(int argc, char* argv[]) { execTime = std::chrono::duration_cast(Time::now() - startTime).count(); processedFramesN += batchSize; + + if (FLAGS_rfreq > 0) { + int64_t nextRunFinishTime = 1/FLAGS_rfreq * processedFramesN * 1.0e9; + std::this_thread::sleep_for(std::chrono::nanoseconds(nextRunFinishTime - execTime)); + } } // wait the latest inference executions